UI控件(UITextField)
2016-02-09 19:13
465 查看
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UITextField* textField1 = [[UITextField alloc] init]; //设置代理表示实现协议 UITextFieldDelegate textField1.delegate = self; textField1.frame = CGRectMake( 20, 120, 280, 30 ); // 边框样式 // typedef enum { // UITextBorderStyleNone, 无边框 // UITextBorderStyleLine, 直线边框 // UITextBorderStyleBezel, 左边框、上边框加粗 // UITextBorderStyleRoundedRect 圆角 // } UITextBorderStyle; textField1.borderStyle = UITextBorderStyleRoundedRect; textField1.text = @"hello,textfield"; textField1.placeholder = @"please input the text"; //设置字体及大小 textField1.font = [UIFont fontWithName:@"Arial" size:10.0f]; //设置字体颜色 textField1.textColor = [UIColor blueColor]; // typedef enum { // UITextFieldViewModeNever, 重不出现 // UITextFieldViewModeWhileEditing, 编辑时出现 // UITextFieldViewModeUnlessEditing, 除了编辑外都出现 // UITextFieldViewModeAlways 一直出现 // } UITextFieldViewMode; textField1.clearButtonMode = UITextFieldViewModeAlways; //采用星号加密显示 textField1.secureTextEntry = NO; //定义弹出的软键盘类型 //UIKeyboardTypeDefault 默认全部 //UIKeyboardTypeNumberPad 数字键盘 //类型较多,此处省略 textField1.keyboardType = UIKeyboardTypeDefault; //定义软键盘上的回车按键的样式 // UIReturnKeyDefault, 默认 灰色按钮,标有Return // UIReturnKeyGo, 标有Go的蓝色按钮 // 类型较多此处省略 textField1.returnKeyType = UIReturnKeyDefault; //左侧或右侧增加图片 UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"person.png"]]; textField1.leftView=image; textField1.leftViewMode = UITextFieldViewModeAlways; [self.view addSubview:textField1]; } #pragma mark - TextField Delegates //开始编辑时出发回调 -(void)textFieldDidBeginEditing:(UITextField *)textField{ NSLog(@"%s", __FUNCTION__); } //结束编辑时出发回调(软键盘消失) -(void)textFieldDidEndEditing:(UITextField *)textField{ NSLog(@"%s", __FUNCTION__); } //回车时被回调 -(BOOL) textFieldShouldReturn:(UITextField *)textField{ NSLog(@"%s", __FUNCTION__); [textField resignFirstResponder];//若该行注释则软件盘在回车后部消失 return YES; } @end
相关文章推荐
- java.io.FileNotFoundException 和 requestFeature() must be called before adding content
- 团队建设(Team building)就是等于组织大家一起吃饭娱乐吗?
- UIView 与 CALayer
- iOS之UI--CAGradientLayer
- Android开发学习之路--UI之自定义布局和控件
- Android开发学习之路--UI之自定义布局和控件
- iOS之UI--CAShapeLayer
- Android studio设置requestWindowFeature(Window.FEATURE_NO_TITLE);出错
- LeetCode题解:Longest Consecutive Sequence
- easyui-datagrid 报错:TypeError: col is null
- 2.UIView的认识
- 1.UI
- UITableView控件didSelectRow和didDeselectRow方法注意事项
- 1007. Maximum Subsequence Sum (25)
- STL 整理(map、set、vector、list、stack、queue、deque、priority_queue)
- Ubuntu 14.04LTS Gnome GUI初体验及163更新源配制
- PriorityQueue源码及用法
- UE4使用Visual Studio编译配置详解
- UITableViewCell优化的几点注意
- SpeedTree - 导入模型到UE4