IOS UITextView limit

Source: Internet
Author: User

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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.