Is there an easy way to disable a UITextField
in code?
My app has 12 UITextField
that are all turned on by default, but when a change is detected in my Segment Control I want to disable some of the UITextField
depending on what Segment the user picks.
Just need to know how to disable it or make it non-editable?
Thanks
Use the enabled: property of the TextField widget by setting it to false : TextField( enabled: false, ... ) This field won't respond to onTap events - it is similar to a disabled field in HTML.
In Objective-C:
textField.enabled = NO;
In Swift:
textField.isEnabled = false
Reference: UIControl.isEnabled
If you also want to indicate that the text field is disabled you should add more code:
if using UITextBorderStyleRoundedRect, you can only gray out text:
textField.enabled = NO; textField.textColor = [UIColor lightGrayColor];
if using any other style, you can also gray out background:
textField.enabled = NO; textField.backgroundColor = [UIColor lightGrayColor];
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