Uitextview and uitextfield statistical characters and Response Return keys

Source: Internet
Author: User
Uitextview and uitextfield statistical characters and Response Return keys

Statistical characters:

1. uitextview

-(Void) textviewdidchange :( uitextview *) textview {int COUNT = [textview. Text length]; // here the count is the number of characters}
Copy code

2. uitextfield

Method 1:

Add a response method for the editing changed event of uitextfield first.

 

-(Ibaction) valuechange // m_textfield is an iboutlet {int COUNT = [m_textfield.text length] of uitextfield. // count indicates the current number of characters. // The number of characters below is limited to 140. If ([m_textfield.text length]> 140) {[m_textfield settext: [m_textfield.text substringtoindex: 140]; // only the first 140 characters are allowed for an extra 140 characters }}
Copy code

Method 2:

In the proxy method:-(Bool) textfield :( uitextfield *) textfield shouldchangecharactersinrange :( nsange) range replacementstring :( nsstring *) string, JudgeThe value of range. length to determine whether the input is a return or other characters.

 

Response Return key:

 

1. uitextview

// Proxy method

-(Bool) textview :( uitextview *) textview shouldchangetextinrange :( nsange) range replacementtext :( nsstring *) text {if (1 = range. length) {// press the return key return yes;} If ([text isequaltostring: @ "\ n"]) {// press the return key // hide the keyboard here, [textview resignfirstresponder]; return no;} else {If ([textview. text length] <140) {// determines the number of characters return yes;} return no ;}
Copy code

2. uitextfield

There is a proxy method.

 

- (BOOL)textFieldShouldReturn:(UITextField *)textField


Post from: http://www.cnblogs.com/dark-angel/archive/2011/11/15/2250029.html

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.