// 创建一个textField
UITextField *userNameTextField = [[UITextField alloc]initWithFrame:KFrame(0, 80, 200, 30)];
// 添加提示文字
userNameTextField.placeholder = @"请输入登录密码";
// 每输入一个字符就变成点,用密码输入
userNameTextField.secureTextEntry = YES;
// 设置return关键字
userNameTextField.returnKeyType = UIReturnKeyGo;
// 设置边框样式
userNameTextField.borderStyle = UITextBorderStyleRoundedRect;
// 设置对齐方式
userNameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
// 设置键盘类型
userNameTextField.keyboardType = UIKeyboardAppearanceDefault;
// 设置代理回收键盘
userNameTextField.delegate = self;
NSLog(@"userNameTextField = %@",userNameTextField);// 输出地址
// 设置键盘不弹出
//userNameTextField.inputView = [[UIView alloc] initWithFrame:CGRectZero];
代理方法: 需要在.h文件里面添加协议
//输入前调用
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//textField.frame = CGRectMake(20, 20, 150, 30);
return YES;
}
// 按return执行
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
NSLog(@"textField = %@",textField);
NSLog(@"%s",__func__);
// 回收键盘
[textField resignFirstResponder];
return YES;
}