ios – Making a wheel picker with aligned icons?

0
105


Do that method utilizing a devoted struct Language, a HStack
and assuming you may have the suitable
flag photographs in your Belongings.xcassets. Works effectively for me.

struct Language: Identifiable {
    let id = UUID()
    var title: String
    var flag: String
}

struct ContentView: View {
    @State non-public var selectedLanguage = "English"
    let languages = [Language(name: "English", flag: "gb"),
                     Language(name: "Italiano", flag: "it"),
                     Language(name: "Français", flag: "fr"),
                     Language(name: "Deutsche", flag: "de")]
    
    var physique: some View {
        Picker("Choose Language", choice: $selectedLanguage) {
            ForEach(languages) { language in
                HStack {
                    Picture(language.flag).resizable().body(width: 35, top: 25)
                    Textual content(language.title)
                    Spacer()
                }.tag(language.title)
            }
        }
        .pickerStyle(.wheel)
        .body(width: 300, top: 150)
    }
}

enter image description here

Be aware, you possibly can put the Spacer() earlier than the Textual content(language.title) for those who want, or each earlier than and after. In that case it offers you this:

enter image description here