@interface ViewController ()<UITextFieldDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//创建UITextField
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(120, 120, 300, 30)];
textField.center = self.view.center;
//设置背景颜色
// textField.backgroundColor = [UIColor grayColor];
//设置边框样式
// textField.borderStyle = UITextBorderStyleRoundedRect;
/**
*
UITextBorderStyleNone,无边框
UITextBorderStyleLine ,有边框
UITextBorderStyleBezel,有边框和阴影
UITextBorderStyleRoundedRect,圆角
*/
//设置背景图片
textField.background = [UIImage imageNamed:@"voice_reply"];
//提示文字
textField.placeholder = @"用户名";
//设置和读取文本内容
textField.text = @"Hello World";
//设置字体
[textField setFont:[UIFont fontWithName:@"黑体" size:17]];
NSLog(@"%@",[UIFont familyNames]);
//密文输入
textField.secureTextEntry = YES;
//键盘类型
//数字键盘
textField.keyboardType = UIKeyboardTypeDefault;
//默认键盘
// textField.keyboardType = UIKeyboardTypeDefault;
//键盘风格
textField.keyboardAppearance = UIKeyboardAppearanceDark;
UITextField *cv = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
cv.backgroundColor = [UIColor redColor];
cv.inputView = cv;
//设置系统键盘或者自定义键盘上的视图
cv.inputAccessoryView = cv;
cv.delegate = self;
//设置左右视图
textField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fengwo_head_icon"]];
textField.leftViewMode = UITextFieldViewModeAlways;
//设置清除按钮显示模式
textField.clearButtonMode = UITextFieldViewModeAlways;
//再次编辑时是否清空之前的内容,默认NO
textField.clearsOnBeginEditing = YES;
//对齐方式
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
textField.font = [UIFont systemFontOfSize:30];
//
textField.adjustsFontSizeToFitWidth = YES;
//设置return键
textField.returnKeyType = UIReturnKeySearch;
//设置输入自动纠正模式
/**
*
UITextAutocapitalizationTypeNone,
UITextAutocapitalizationTypeWords,
UITextAutocapitalizationTypeSentences,
UITextAutocapitalizationTypeAllCharacters,
*/
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
// [self.view addSubview:cv];
[self.view addSubview:textField];
}
-(BOOL)textFieldShouldClear:(UITextField *)textField{
NSLog(@"%s",__func__);
return YES;
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{
NSLog(@"%s",__func__);
return YES;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
NSLog(@"%s",__func__);
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSLog(@"%s",__func__);
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
NSLog(@"should");
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
NSLog(@"%s",__func__);
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
NSLog(@"%s",__func__);
}
UITextField
最新推荐文章于 2017-08-24 09:31:58 发布