iOS 限制输入字数完美解决方案
作者:
爱上火烧的小毛驴 | 来源:发表于
2017-04-26 17:43 被阅读40次- (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];
}
}
}
本文标题:iOS 限制输入字数完美解决方案
本文链接:https://www.haomeiwen.com/subject/xhhwzttx.html
网友评论