您的位置:首页 > 产品设计 > UI/UE

不错的判断 UITextView 内容不超过20个字符串的方法

2016-02-18 20:52 483 查看
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

if ([text isEqualToString:@"\n"]){
[self onSendBarrage:nil];
return YES;
}
NSMutableAttributedString *attrM = [[NSMutableAttributedString alloc]initWithAttributedString:textView.attributedText];
if (textView == self.textFieldBarrage)
{
if (attrM.length > MAX_INPUT_LEN) {
NSRange range = NSMakeRange(0, MAX_INPUT_LEN);
textView.attributedText = [attrM attributedSubstringFromRange:range];
}
[self fixChatButtonStateWithTextViewLength:attrM.length];
}
return YES;
}


以上代码的好处主要在于,先提前计算用户输入的内容,再根据推断出的输入框结果,对输入框的字符进行截取.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: