UITextFieldDelegate協議,uitextfielddelegate

來源:互聯網
上載者:User

UITextFieldDelegate協議,uitextfielddelegate

 

很多人都認為UITextField很簡單,為什麼會寫這個協議呢?

因為在實際開發中可能會用到;

 

比如要做到的效果:

文字框下面的底線的顏色要隨著輸入的狀態變化;

點擊對應的文字框,其下面的線條變為綠色,結束編輯,變為灰色;

要熟悉UITextFieldDelegate協議才能做到這一點;

首先,先看一下官方的說明:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;        // return NO to disallow editing.- (void)textFieldDidBeginEditing:(UITextField *)textField;           // became first responder- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;          // return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end- (void)textFieldDidEndEditing:(UITextField *)textField;             // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;   // return NO to not change text- (BOOL)textFieldShouldClear:(UITextField *)textField;               // called when clear button pressed. return NO to ignore (no notifications)- (BOOL)textFieldShouldReturn:(UITextField *)textField;              // called when 'return' key pressed. return NO to ignore.

 

1、

- (void)textFieldDidBeginEditing:(UITextField *)textField;

文字框已經開始編輯

2、

- (void)textFieldDidEndEditing:(UITextField *)textField; 

文字框已經結束編輯

 

3、其他設定是否允許的輸入控制

1、- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;        // return NO to disallow editing.
//控制是否允許輸入,傳回值是NO的時候,禁止輸入;

2、- (BOOL)textFieldShouldEndEditing:(UITextField *)textField; // return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end //是否結束輸入,傳回值是YES時候,允許停止輸入,並且釋放第一響應;返回NO的時候,則相反;3、- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; // return NO to not change text
//是否改變輸入文本,返回NO的時候,不儲存修改
4、- (BOOL)textFieldShouldClear:(UITextField *)textField; // called when clear button pressed. return NO to ignore (no notifications)
//當清空按鈕時候調用,返回是NO的時候,忽視清空
5、- (BOOL)textFieldShouldReturn:(UITextField *)textField; // called when 'return' key pressed. return NO to ignore.
   //當點擊return按鈕時候調用該方法,返回是NO的時候,不做任何響應;

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.