下面是UITextField的一些常用属性,代码与注释结合在一起总结,如若发现有遗漏会继续补充
UITextField *textField = [[UITextField alloc]init]; //初始化
//输入框大小
textField.frame = CGRectMake(50, 88, self.view.frame.size.width - 100, 50);
//hint 字体
textField.placeholder = @"测试";
//是否是密码
// textField.secureTextEntry = false
//边框 以下都是两种方法显示
// textField.borderStyle = UITextBorderStyleRoundedRect;
[textField setBorderStyle:UITextBorderStyleRoundedRect];
//显示清除按钮 点开枚举可以看有多少种类型
// textField.clearButtonMode = UITextFieldViewModeNever;
[textField setClearButtonMode:UITextFieldViewModeWhileEditing];
//Adjust to fit 用于指定字号大小是否随文本的减小而减小
// [textField setAdjustsFontSizeToFitWidth:true];
textField.adjustsFontSizeToFitWidth = true;
//设置最小字体
// [textField setMinimumFontSize:12];
textField.minimumFontSize = 12;
//该属性控制是否文本框内的文本大小写
// textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
[textField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
//自动更正是否正确
// textField.autocorrectionType = UITextAutocorrectionTypeDefault;
[textField setAutocorrectionType:(UITextAutocorrectionTypeDefault)];
//键盘类型
// textField.keyboardType = UIKeyboardTypeNamePhonePad;
[textField setKeyboardType:UIKeyboardTypeNamePhonePad];
//Return Key
// textField.returnKeyType = UIReturnKeyDone;
[textField setReturnKeyType:UIReturnKeyDone];
//设置View 用于自定义关闭键盘
// textField.inputAccessoryView = ..;
[self.view addSubview:textField];