UITextField
2016-09-19 16:07
239 查看
@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限制输入金额是正确小数
- iOS开发之自定义UITextField的方法
- iOS App开发中UITextField组件的常用属性小结
- iOS应用开发中使UITextField实现placeholder属性的方法
- 解决iOS7上UITextField限制字数输入导致崩溃问题的方法
- IOS UI学习教程之设置UITextField各种属性
- Swift社交应用文本输入优化汇总
- 修改UITextField的placeHolder的颜色及字体大小
- UITextField常用delegate
- UITextField
- iOS开发1:UITextField控件属性
- iOS UITextField 拾遗(下)
- [Swift]UIKit学习之UITextField的用法
- IOS开发Swift语言UITextField设置靠左的间距
- IOS开发Swift语言键盘遮挡输入框(UITextField)
- iOS UITextField相关
- UIKit,UIView
- iOS关于系统键盘的长度限制
- cocos2d-x 一些有用的函数
- UITextField的使用