码迷,mamicode.com
首页 > 移动开发 > 详细

iOS UITextFieldDelegate协议

时间:2015-07-28 18:15:33      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

 

很多人都认为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.
//控制是否允许输入

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 //是否结束输入 3、- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; // return NO to not change text
//是否改变输入文本
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的时候,不做任何响应

 

iOS UITextFieldDelegate协议

标签:

原文地址:http://www.cnblogs.com/jukaiit/p/4683365.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!