I am trying to disable an option of Picker in swiftUI. According documentation below code is suppose to work:
struct ContentView: View {
let options = ["All", "Men", "Women", ]
@State private var selectedOption = "All"
var body: some View {
Picker("Options", selection: $selectedOption) {
ForEach(options, id: \.self) { option in
Text(option)
.disabled(option == "All")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Unfortunately, It's not working where I have went wrong. Can anyone help!?
With iOS 17/macOS 14 selectionDisabled(_:) has been introduced which has the intended effect of keeping the item visible in the picker but disallowing selection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With