iphone - 强制 UITextField 不可编辑,如 UITextView 的 'editable' 属性

标签 iphone ios ipad uitextfield

我想要一个不能编辑的UITextField,但用户可以将光标放在其中。这意味着当光标在UITextField中时,您可以查看UITextField中的文本,但不能修改它的内容,比如 UITextView 的 editable 属性。由于各种原因,我不能使用 UITextView,所以请帮助我。

tacticNameView = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 161, 23)];
tacticNameView.backgroundColor = [UIColor clearColor];
tacticNameView.textAlignment = UITextAlignmentCenter;
tacticNameView.enabled = NO;

'enabled' 属性没有解决我的问题,所以请帮助我。

最佳答案

使用这个委托(delegate)方法

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

关于iphone - 强制 UITextField 不可编辑,如 UITextView 的 'editable' 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6276887/

相关文章:

ios - 省略了 ObjectiveC 的 clang AST 中的代码块

iphone - iOS 7 中的文本和字符串绘制系统更改是否有概述?

当方向只允许横向时,iOS 9 UIImagePickerControllerSourceTypePhotoLibrary 崩溃

iphone - 在 iPhone 上获取流媒体视频的屏幕截图

iphone - 单击警报 View 中的按钮时如何关闭警报 View

ios - 使用 dequeueReusableCellWithIdentifier 不会显得更快(或更低的内存)?

ios - 在 UINavigationBar 的子类中设置 backButton 框架

iphone - iPhone 4S 上的空 IMEI 号码

iphone - UIButton setImage 不起作用?

ios - AES 加密到奇怪的字符