【问题标题】:Move UITextView caret to new line when user enter 29 character?当用户输入 29 个字符时,将 UITextView 插入符号移动到新行?
【发布时间】: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 个字符,然后将他带到换行符。

提前致谢。

【问题讨论】:

标签: ios uitextview uitextviewdelegate


【解决方案1】:

如果我没听错的话。您需要在 shouldChangeTextInRange: 方法中实现接下来的几行。

if (range. location%29==0) {
//add new line
}

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 2018-12-21
    • 2019-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多