iOS之UI学习-UITextField属性篇

- (void)viewDidLoad { 

     [super viewDidLoad];

     //须知:UITextField继承于UIcontrol,而UITextView继承于UIScrollView,UIScrollView又继承于UIView 

     //创建输入框 UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 50, 280, 100)];


     //设置输入框的边框样式(共四种样式) 

     // textField.borderStyle = UITextBorderStyleNone; 没有边框样式

     // textField.borderStyle = UITextBorderStyleLine; 边框是黑线 

     // textField.borderStyle = UITextBorderStyleBezel; 边框线类似于灰线

     textField.borderStyle = UITextBorderStyleRoundedRect; //边框是圆角的,背景颜色默认是白色的


     //设置输入框在没有内容时候的提示文字

     textField.placeholder = @"输入框没有内容时的提示内容";


     //设置字体的样式和大小

     textField.font = [UIFont fontWithName:@"Arial" size:16];


     //设置输入框的最右边的删除按钮(共四种情况)

     // textField.clearButtonMode = UITextFieldViewModeNever; 不显示删除按钮

     // textField.clearButtonMode = UITextFieldViewModeWhileEditing; 编辑的时候显示删除按钮

     // textField.clearButtonMode = UITextFieldViewModeUnlessEditing; 只在编辑的时候不显示删除按钮

     textField.clearButtonMode = UITextFieldViewModeAlways; //只要有内容存在则存在删除按钮 


     //隐藏输入的字符

     textField.secureTextEntry = NO;


     //再次编辑清空上一次内容

     textField.clearsOnBeginEditing = YES;


     //自动纠错

     textField.autocorrectionType = UITextAutocorrectionTypeDefault; //默认

     // textField.autocorrectionType = UITextAutocorrectionTypeNo; 不自动纠错

     // textField.autocorrectionType = UITextAutocorrectionTypeYes; 自动纠错 


     //设置这两项之后,字符数量超出之后,全部的字符的大小会变到设置的最小值

     textField.adjustsFontSizeToFitWidth = YES; 

     textField.minimumFontSize = 9; 


     //设置进行输入时候的键盘类型 

     textField.keyboardType = UIKeyboardTypeDefault;

     // textField.keyboardType = UIKeyboardTypeASCIICapable;                    支持ASCII的键盘

     // textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;   包含数字和一些#等字符的键盘

     // textField.keyboardType = UIKeyboardTypeURL;                                    带有.com的键盘

     // textField.keyboardType = UIKeyboardTypeNumberPad;                        纯数字键盘

     // textField.keyboardType = UIKeyboardTypePhonePad;                          电话键盘(数字键盘和带有#*的键盘)

     // textField.keyboardType = UIKeyboardTypeNamePhonePad;                 以下的键盘都类似

     // textField.keyboardType = UIKeyboardTypeEmailAddress;

     // textField.keyboardType = UIKeyboardTypeDecimalPad;

     // textField.keyboardType = UIKeyboardTypeTwitter;

     // textField.keyboardType = UIKeyboardTypeWebSearch;

     // textField.keyboardType = UIKeyboardTypeAlphabet; 


     //键盘的return键 

     textField.returnKeyType = UIReturnKeyDefault;             //在这些类型中,最后一个单词是什么则显示什么

     // textField.returnKeyType = UIReturnKeyGo;

     // textField.returnKeyType = UIReturnKeyGoogle;

     // textField.returnKeyType = UIReturnKeyJoin;

     // textField.returnKeyType = UIReturnKeyNext;

     // textField.returnKeyType = UIReturnKeyRoute;

     // textField.returnKeyType = UIReturnKeySearch;

     // textField.returnKeyType = UIReturnKeySend;

     // textField.returnKeyType = UIReturnKeyYahoo;

     // textField.returnKeyType = UIReturnKeyDone;

     // textField.returnKeyType = UIReturnKeyEmergencyCall;

     // textField.returnKeyType = UIReturnKeyContinue;


     //键盘的外观 textField.keyboardAppearance = UIKeyboardAppearanceDefault;

     // textField.keyboardAppearance = UIKeyboardAppearanceDark; 黑色键盘

     // textField.keyboardAppearance = UIKeyboardAppearanceLight; 白色键盘

     // textField.keyboardAppearance = UIKeyboardAppearanceAlert; 黑色键盘 


     //内容的首字母是否大写 

     textField.autocapitalizationType = UITextAutocapitalizationTypeNone;                  //不自动改成大写

     // textField.autocapitalizationType = UITextAutocapitalizationTypeWords;             将单词的首字母大写

     // textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;       将句子的首字母大写

     // textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;  所有字母都大写 


    //添加到当前视图 [self.view addSubview:textField];

}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值