SwiftUIRadioButtons

main

imokhtar/SwiftUIRadioButtons

SwiftUIRadioButtons

Radio buttons collection views written puerly in SwiftUI follwing its philshophy.

Components:

HRadioCollection:

a structure that renders a horizontal collection of radio buttons given a collection of identifaiable data.

VRadioCollection:

a structure that renders a vertical collection of radio buttons given a collection of identifaiable data.

How to Use:

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


struct SelectCountryView: View {
    @State private var selectedCountry: Country? = nil
    private let countries = [
        Country(imageName: "egypt_flag", label: "Egypt"),
        Country(imageName: "aue_flag", label: "UAE"),
        Country(imageName: "ksa_flag", 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

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Oct 20 2024 00:42:17 GMT-0900 (Hawaii-Aleutian Daylight Time)