IOS UITextView limit
// UITextVIew input box
Self. contentTV = [[UITextView alloc] initWithFrame: CGRectMake (0, lineVIewOne. frame. origin. y + lineVIewOne. frame. size. height + 1, self. view. frame. size. width, 160)];
Self. contentTV. backgroundColor = [UIColor whiteColor];
Self. contentTV. textAlignment = NSTextAlignmentLeft;
// Self. contentTV. text = @ "What problems do you encounter during use? You can give us feedback in a timely manner! ";
Self. contentTV. font = [UIFont systemFontOfSize: 14.0];
Self. contentTV. keyboardType = UIKeyboardTypeNamePhonePad;
Self. contentTV. clearsOnInsertion = YES;
[Self. view addSubview: self. contentTV];
Self. contentTV. delegate = self;
Self. placehoderLabel = [[UILabel alloc] initWithFrame: CGRectMake (0, 0, self. contentTV. frame. size. width, 30)];
Self. placehoderLabel. backgroundColor = [UIColor whiteColor];
Self. placehoderLabel. text = @ "What problems do you encounter during use? You can give us feedback in a timely manner! ";
// Self. placehoderLabel. alpha = 0.5;
// Self. placehoderLabel. textAlignment = NSTextAlignmentCenter;
Self. placehoderLabel. font = [UIFont systemFontOfSize: 13.0];
[Self. contentTV addSubview: self. placehoderLabel];
# Pragma mark-UITextViewDelegate
-(BOOL) textView :( UITextView *) textView shouldChangeTextInRange :( nsange) range replacementText :( NSString *) text
{
NSString * temp = [textView. text
StringByReplacingCharactersInRange: range
WithString: text];
NSInteger remaintextnum= 100;
// Calculate the remaining number of words that can be entered
If (range. location> = 100)
{
RemainTextNum = 0;
[Self showSimpleAlert: @ "Enter less than 100 words! "];
Self. emailFT. userInteractionEnabled = NO;
Return YES;
}
Else
{
NSString * nsTextContent = temp;
NSInteger existTextNum = [nsTextContent length];
RemainTextNum = 100-existTextNum;
Self. label = [[UILabel alloc] initWithFrame: CGRectMake (textView. frame. size. width-80, textView. frame. size. height-30, 80, 30)];
Self. label. textAlignment = NSTextAlignmentCenter;
[TextView addSubview: self. label];
Self. label. backgroundColor = [UIColor whiteColor];
Self. label. text = [NSString stringWithFormat: @ "% ld/100", (long) remainTextNum];
Return YES;
}
}
When you enter it, the label displays the remaining words.