方式
设置代理 <UITextFieldDelegate,UITextViewDelegate>
xx.delegate = self;
- UITextView
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text{
/** 如果输入“return”,失去焦点*/
if([text isEqualToString:@"\n"]){
[textView resignFirstResponder];
}
return YES;
}
- UITextField
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
/** 如果输入的是回撤,直接放弃焦点*/
if([string isEqualToString:@"\n"]){
[textField resignFirstResponder];
}
return YES;
}
网友评论