[nameTF addTarget:self action:@selector(reTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];.net
- (void)reTextFieldDidChange:(UITextField *)textField{//輸入文本時調用ci
UITextRange *selectedRange = [textField markedTextRange];get
NSString * newText = [textField textInRange:selectedRange];string
//獲取高亮部分it
if(newText.length>0) return;io
//不容許輸入空格class
textField.text = [textField.text stringByReplacingOccurrencesOfString:@" " withString:@""];select
if (textField == _nameTF) {//文本框最大長度di
textField.text = textField.text.length > 16 ? [textField.text substringToIndex:16] : textField.text;new
}
}