首页 > 其他 > 详细

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

时间:2014-09-04 13:21:39      阅读:413      评论:0      收藏:0      [点我收藏+]

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];

}  

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

原文:http://blog.csdn.net/hakusan/article/details/39050917

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!