Swiftpack.co - Package - 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

Github

link
Stars: 4

Dependencies

Used By

Total: 0