Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-editable UITextField with copy menu

Is there a way to make a UITextField non-editable by the user and provide only a copy menu without subclassing? I.e when the text field is touched it automatically selects all the text and only shows the copy menu.

If possible to do this without subclassing what are the interface builder options that need to be selected?

Thanks in advance.

like image 437
cubiclewar Avatar asked Jun 06 '11 10:06

cubiclewar


2 Answers

simply do:

(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    return NO;
}

and also:

yourTextField.inputView = [[UIView alloc] init];
like image 183
blackSon Avatar answered Oct 19 '22 11:10

blackSon


You can disable editing by setting the enabled property of UITextField to NO.

textField.enabled = NO;

Note that doing this will also disable the copy/paste options. What you are asking for has been discussed before in this solution: Enable copy and paste on UITextField without making it editable

like image 26
Jhaliya - Praveen Sharma Avatar answered Oct 19 '22 12:10

Jhaliya - Praveen Sharma