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