- (void)textFieldDidChange:(UITextField *)textField
{
if (textField == self.textFieldName) {
if (textField.text.length > 15) {
UITextRange *markedRange = [textField markedTextRange];
if (markedRange) {
return;
}
//Emoji占2个字符,如果是超出了半个Emoji,用15位置来截取会出现Emoji截为2半
//超出最大长度的那个字符序列(Emoji算一个字符序列)的range
NSRange range = [textField.text rangeOfComposedCharacterSequenceAtIndex:15];
textField.text = [textField.text substringToIndex:range.location];
}
}
}
网友评论