Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting UITextField not editable or editable

Tags:

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;
}
like image 443
Anand - Avatar asked Apr 23 '15 11:04

Anand -


People also ask

How do you make a text field non editable in Swift?

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.


1 Answers

You can enable or disable user interaction on the textfield using this property:

textField.userInteractionEnabled = NO;

In Swift 5

textField.isUserInteractionEnabled = false
like image 163
Sumit Sharma Avatar answered Sep 17 '22 08:09

Sumit Sharma