I want to know how to disable UITextField
, i.e I placed a UIButton
in the frame of UITextField
for design purpose.
When I tap my button in UITextField
the keyboard appears, but I don't want the keyboard to be displayed!
Here is my code so far:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
return textField !=textfiled1;
return textField !=textfiled2;
}
You should have a Bool Variable. Set it to 'false' then when the button is pressed you toggle it to 'true'. Depending on its state just run to different methods which essentially allows you to edit or not.
You can enable or disable user interaction on the textfield using this property:
textField.userInteractionEnabled = NO;
In Swift 5
textField.isUserInteractionEnabled = false
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