//创建
UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(50, 200, 200, 50)];
[self.view addSubview:textFiled];
//设置边框
textFiled.borderStyle = UITextBorderStyleRoundedRect;
//设置编辑框中的内容
// textFiled.text = @"lanou";
//设置编辑框的默认内容
textFiled.placeholder = @"I love you";
//设置内容对齐方式
textFiled.textAlignment = NSTextAlignmentCenter;
//设置删除内容按钮
textFiled.clearButtonMode = UITextFieldViewModeAlways;
//设置开始编辑时删除原有内容
textFiled.clearsOnBeginEditing = YES;
//设置文本框的代理
textFiled.delegate = self;
//设置return键的样式
textFiled.returnKeyType = UIReturnKeyGo;
//设置键盘的样式
textFiled.keyboardType = UIKeyboardTypeDefault;
//设置是否密文输入
// textFiled.secureTextEntry = YES;
//自定义键盘
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 80)];
view.backgroundColor = [UIColor redColor];
// textFiled.inputView = view;
//自定义辅助键盘
UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 50)];
subView.backgroundColor = [UIColor greenColor];
textFiled.inputAccessoryView = subView;
//左视图模式
textFiled.leftViewMode = UITextFieldViewModeAlways;
//设置左视图
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
label1.text = @"号码:";
label1.backgroundColor = [UIColor redColor];
textFiled.leftView = label1;
UI基本控件---UITextField
最新推荐文章于 2018-09-11 13:37:26 发布