//品牌输入框
[self.inputPinPaiTextField addTarget:self action:@selector(pailTextFieldChangeValue:) forControlEvents:UIControlEventEditingChanged];
pragma mark - 输入文本框的点击事件
//品牌输入框:10字限制
-
(void)pailTextFieldChangeValue:(UITextField*)textField{
UITextRange *selectedRange = [textField markedTextRange];
//获取高亮部分
UITextPosition *pos = [textField positionFromPosition:selectedRange.start offset:0];//如果在变化中是高亮部分在变,就不要计算字符了
if (selectedRange && pos) {
return;
}
NSUInteger count = textField.text.length;
if (count > 10) {
self.inputPinPaiTextField.text = [textField.text substringToIndex:10];
}
}
网友评论