SwiftUI - Picker Example
Example of using a Picker
in SwiftUI - Popup with the picker data
import SwiftUI
struct ContentView : View {
var companyNames = ["Apple", "Microsoft", "Google"]
@State var selectedCompany = 0
var body: some View {
NavigationView {
Form {
Section {
Picker(selection: $selectedCompany, label: Text("Company")) {
ForEach(0 ..< companyNames.count) {
Text(self.companyNames[$0]).tag($0)
}
}
}
}.navigationBarTitle(Text("Select your company"))
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
No comments: