SwiftUIRadioButtons 0.1.1

SwiftUIRadioButtons 0.1.1

Ahmed Mokhtar 维护。



  • 作者:
  • 作者

SwiftUIRadioButtons

使用 SwiftUI 编写的纯广播按钮集合视图。

组件

HRadioCollection

一个结构,给定可识别数据的集合来渲染一个水平的广播按钮集合。

VRadioCollection

一个结构,给定可识别数据的集合来渲染一个垂直的广播按钮集合。

如何使用

struct Country: Identifiable {
    let id = UUID()
    var imageName: String
    var label: String
}


struct SelectCountryView: View {
    @State private var selectedCountry: Country? = nil
    private let countries = [
        Country(imageName: "Egypt", label: "Egypt"),
        Country(imageName: "aue_flag", label: "UAE"),
        Country(imageName: "Saudi-Arabia", label: "KSA"),
    ]
    
    var body: some View {
        VStack {
            Text(selectedCountry?.label ?? "No selection yet")
            HRadioCollection(selectedData: $selectedCountry, data: countries) { country in
                HStack {
                    Image(country.imageName)
                    Text(country.label)
                        .font(Font.system(size: 14.relativeHeight))
                        .bold()
                }
            }
            .radioForegroundColor(.red)
            .padding()
        }
    }
}

 Alt text