禁止仅对UITextField进行编辑?

问题描述:

我尝试以下方法:禁止仅对UITextField进行编辑?

  • 性能enabled和 “用户交互启用”;

  • 方法textFieldShouldBeginEditing:

但他们禁用所有可能的操作与文本字段。我只需要禁用编辑,但允许用户复制文本值。如何实现这一点?

推荐推荐速递该应用还没有任何解决方法。尝试

YourTextField.editing = NO; 

除了tasuhka的响应,确保 YourTextField.selectable = YES;

实施并设置以下UITextFieldDelegate

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

这使得该领域不可编辑的同时仍保留该选择/复制功能。 editing属性是只读和无关的。