2011-06-08 83 views
0

我想为UITextField不能编辑,但用户可以将光标,这意味着,当光标在的UITextField,你可以查看UITextField中的文本,但不能修改其内容,如UITextView的可编辑属性。我不能使用UITextView出于各种原因,所以请帮助我。强制的UITextField是不可编辑样的UITextView的“编辑”属性

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

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

回答

1

使用该委托的方法

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

您可以使用该委托的方法。

-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField{ 
     return NO; 
} 

,也可以删除使用

textfield.userInteractionEnabled = NO; 
的文本框的交互