【发布时间】:2015-10-14 07:42:52
【问题描述】:
我只想要 UITextView 中的 3 行。每行最多29个字符
我做的是
static const NSUInteger MAX_NUMBER_OF_LINES_ALLOWED = 3;
NSMutableString *t = [NSMutableString stringWithString: self.addressTextView.text];
[t replaceCharactersInRange: range withString: text];
NSUInteger numberOfLines = 0;
for (NSUInteger i = 0; i < t.length; i++) {
if ([[NSCharacterSet newlineCharacterSet] characterIsMember: [t characterAtIndex: i]]) {
numberOfLines++;
}
}
return (numberOfLines < MAX_NUMBER_OF_LINES_ALLOWED);
在下面的委托方法中
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
请告诉我如何将每行的长度限制为最多 29 个字符。
也就是说,如果用户在第一行输入 29 个字符,然后将他带到换行符。
提前致谢。
【问题讨论】:
-
看到这个链接可能对你有帮助stackoverflow.com/questions/27475670/…
标签: ios uitextview uitextviewdelegate