UITextField常用属性与回收UITextfield的键盘

UITextField UIControl的子类,UIControl又是UIView的子类,所以也是一个视图,只不过比UIView多了两个功能,1.文字显示,2.文本编辑   

使用过程分四步:   

1.创建对象   

2.配置属性   

3添加到父视图   

4.释放所有权      

1.创建对象   

UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(50, 50, 180, 50)];    text.backgroundColor = [UIColor yellowColor];    [_view addSubview:text];    [text release];

2.设置text的边框样式(圆角)   

text.borderStyle = UITextBorderStyleRoundedRect;       

3.设置text默认显示文字(但是不作为文本内容的一部分)   

text.placeholder = @"请输入用户名";       

4.设置text文字   

text.text = @"什么破烂;


5. 设置文本颜色    

text.textColor = [UIColor blackColor];

6.设置文本的对齐方式   

text.textAlignmentNSTextAlignmentCenter;

7.设置文字字体   

text.font = [UIFont  systemFontOfSize:18];     

8.设置输入框是否可编辑   

text.enabled = YES;

9.设置当开始编辑时,是否清除框中内容   

text.clearsOnBeginEditing = YES;       

10.设置密码格式(输入框中内容是否以点的形式显示)   

text.secureTextEntry = YES;       

11.设置弹出键盘的样式(数字键盘)   

text.keyboardType = UIKeyboardTypeNumberPad;       

12.键盘右下角显示样式   

text.returnKeyType = UIReturnKeyGo;


13.设置tag值
text.tag = 120;


14.键盘回收


1.点击右下角或者回车回收键盘
1.设置代理
text. delegate = self ;

2.服从协议
在相应.h文件添加协议,如
@interface MAYAppDelegate : UIResponder < UIApplicationDelegate , UITextFieldDelegate >
服从,<UITextFieldDelegate >协议

3.实现协议中的方法
 - ( BOOL )textFieldShouldReturn:( UITextField *)textField

{  

   回收键盘,取消第一响应者   

  [textField resignFirstResponder];    return YES;

}

2.点击空白处回收键盘
1.设置代理
text.delegate = self;

2.服从协议
在相应的.h文件中添加协议,如
@interface  MAYAppDelegate :  UIResponder  < UIApplicationDelegate , UITextFieldDelegate >
服从,<UITextFieldDelegate >协议

3.实现协议中的方法

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

  [text resignFirstResponder];

}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值