限制HPGrowingTextView的字符数

时间:2013-04-11 12:14:36

标签: objective-c xcode

我正在使用HPGrowingTextView。我如何限制输入的字符数。例如,如果我设置100,那么用户不应该在上面输入100.谢谢提前

1 个答案:

答案 0 :(得分:1)

在HPGrowingTextView.m

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
 replacementText:(NSString *)atext

{

//place on top below line of code

  NSInteger newTextLength = [textView.text length] - range.length + [atext length];

    if (newTextLength > 160)
    {
        // don't allow changed and limits the characters for eg...160

        return NO;
    }

//keep remaining code unchanged...


}

希望这有助于你..