星空网 > 软件开发 > 操作系统

UITextField属性

1.borderStyle

设置边框样式,只有设置了才会显示边框样式

text.borderStyle = UITextBorderStyleRoundedRect;typedef enum {   UITextBorderStyleNone,    UITextBorderStyleLine,   UITextBorderStyleBezel,   UITextBorderStyleRoundedRect  } UITextBorderStyle;        


2.backgroundColor

设置输入框的背景颜色,此时设置为白色 如果使用了自定义的背景图片边框会被忽略掉 

text.backgroundColor = [UIColor whiteColor];


3.
background

设置背景,注意只有UITextBorderStyleNone的时候改属性有效

//UITextField 的背景text.background = [UIImage imageNamed:@"dd.png"];//设置enable为no时,textfield的背景 text.disabledBackground = [UIImage imageNamed:@"cc.png"];

 

4.placeholder

当输入框没有内容时,提示内容为password

text.placeholder = @"password";

 

5.font

设置输入框内容的字体样式和大小

text.font = [UIFont fontWithName:@"Arial" size:20.0f];

 

6.textColor

设置字体颜色

text.textColor = [UIColor redColor];

 

7.clearButtonMode

输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容

text.clearButtonMode = UITextFieldViewModeAlways; typedef enum {   UITextFieldViewModeNever, //重不出现   UITextFieldViewModeWhileEditing, //编辑时出现   UITextFieldViewModeUnlessEditing, //除了编辑外都出现   UITextFieldViewModeAlways  //一直出现} UITextFieldViewMode;

 

8.text

显示文本框的内容

text.text = @"一开始就在输入框的文字";

 

9.secureTextEntry

每个输入一个字符就变成点 用来输入密码时,设置这个属性

text.secureTextEntry = YES;

 

10.autocorrectionType

是否纠错

text.autocorrectionType = UITextAutocorrectionTypeNo;typedef enum {   UITextAutocorrectionTypeDefault, //默认   UITextAutocorrectionTypeNo, //不自动纠错   UITextAutocorrectionTypeYes, //自动纠错} UITextAutocorrectionType;

 

11.clearsOnBeginEditing

再次编辑就清空

text.clearsOnBeginEditing = YES;

 

12.textAlignment

内容水平对齐方式

text.textAlignment = UITextAlignmentLeft;

 

13.contentVerticalAlignment

内容的垂直对齐方式;UITextField继承自UIControl,此类中有一个属性contentVerticalAlignment

text.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

 

14.adjustsFontSizeToFitWidth

设置为YES时文本会自动缩小以适应文本窗口大小;默认是保持原来大小,而让长文本滚动;

textFied.adjustsFontSizeToFitWidth = YES;//设置自动缩小显示的最小字体大小text.minimumFontSize = 20;

 

15.keyboardType

设置键盘的样式

text.keyboardType = UIKeyboardTypeNumberPad;typedef enum {   UIKeyboardTypeDefault, //默认键盘,支持所有字符            UIKeyboardTypeASCIICapable, //支持ASCII的默认键盘   UIKeyboardTypeNumbersAndPunctuation, //标准电话键盘,支持+*#字符   UIKeyboardTypeURL, //URL键盘,支持.com按钮 只支持URL字符  UIKeyboardTypeNumberPad, //数字键盘  UIKeyboardTypePhonePad, //电话键盘   UIKeyboardTypeNamePhonePad, //电话键盘,也支持输入人名  UIKeyboardTypeEmailAddress, //用于输入电子 邮件地址的键盘       UIKeyboardTypeDecimalPad, //数字键盘 有数字和小数点   UIKeyboardTypeTwitter, //优化的键盘,方便输入@、#字符   UIKeyboardTypeAlphabet //Alphabet} UIKeyboardType;

 

16.autocapitalizationType

首字母是否大写

text.autocapitalizationType = UITextAutocapitalizationTypeNone;typedef enum {   UITextAutocapitalizationTypeNone, //不自动大写   UITextAutocapitalizationTypeWords, //单词首字母大写   UITextAutocapitalizationTypeSentences, //句子的首字母大写   UITextAutocapitalizationTypeAllCharacters, //所有字母都大写} UITextAutocapitalizationType;

 

17.returnKeyType

小键盘中右下角的return键,可以改变成下述类型的键

text.returnKeyType =UIReturnKeyDone;typedef enum {   UIReturnKeyDefault, //默认灰色按钮,标有Return   UIReturnKeyGo, //标有Go的蓝色按钮   UIReturnKeyGoogle, //标有Google的蓝色按钮,用语搜索   UIReturnKeyJoin, //标有Join的蓝色按钮   UIReturnKeyNext, //标有Next的蓝色按钮   UIReturnKeyRoute, //标有Route的蓝色按钮   UIReturnKeySearch, //标有Search的蓝色按钮   UIReturnKeySend, //标有Send的蓝色按钮   UIReturnKeyYahoo, //标有Yahoo的蓝色按钮   UIReturnKeyYahoo, //标有Yahoo的蓝色按钮   UIReturnKeyEmergencyCall, //紧急呼叫按钮} UIReturnKeyType;

 

18.keyboardAppearance

键盘外观

textView.keyboardAppearance=UIKeyboardAppearanceDefault;typedef enum {  UIKeyboardAppearanceDefault, //默认外观,浅灰色  UIKeyboardAppearanceAlert //深灰 石墨色} UIReturnKeyType;

 

19.rightView

最右侧加入一个UIView

UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];text.rightView=image;text.rightViewMode = UITextFieldViewModeAlways;typedef enum {   UITextFieldViewModeNever,   UITextFieldViewModeWhileEditing,   UITextFieldViewModeUnlessEditing,   UITextFieldViewModeAlways} UITextFieldViewMode;

 

20.editing

是否允许编辑

21.delegate

类要遵守UITextFieldDelegate协议text.delegate = self; 声明text的代理是我,我会去实现把键盘往下收的方法 这个方法在UITextFieldDelegate里所以我们要遵守UITextFieldDelegate这个协议

- (BOOL)textFieldShouldReturn:(UITextField *)textField{   [text resignFirstResponder];//主要是[receiver resignFirstResponder]在哪调用就能把receiver(text)对应的键盘往下收  return YES;}- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{    return YES;//返回一个BOOL值,YES代表允许编辑,NO不允许编辑}- (void)textFieldDidBeginEditing:(UITextField *)textField{    //开始编辑时触发,文本字段将成为first responder } - (BOOL)textFieldShouldEndEditing:(UITextField *)textField{      return NO;//要想在用户结束编辑时阻止文本字段消失,可以返回NO }- (void)textFieldDidEndEditing:(UITextField *)textField;{   //上面返回YES后执行;上面返回NO时有可能强制执行(e.g. view removed from window)}
- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{     return YES;//当用户使用自动更正功能,把输入的文字修改为推荐的文字时,就会调用这个方法。}
- (BOOL)textFieldShouldClear:(UITextField *)textField{       return YES;//返回一个BOOL值指明是否允许根据用户请求清除内容 } -(BOOL)textFieldShouldReturn:(UITextField *)textField{    return YES;//返回一个BOOL值,指明是否允许在按下回车键时结束编辑} 

 

22.Notification

UITextField派生自UIControl,所以UIControl类中的通知系统在文本字段中也可以使用。除了UIControl类的标准事件,你还可以使用下列UITextField类特有的事件

UITextFieldTextDidBeginEditingNotification
UITextFieldTextDidChangeNotification
UITextFieldTextDidEndEditingNotification

当文本字段退出编辑模式时触发。通知的object属性存储了最终文本。因为文本字段要使用键盘输入文字,所以下面这些事件发生时,也会发送动作通知。

UIKeyboardWillShowNotification //键盘显示之前发送
UIKeyboardDidShowNotification //键盘显示之后发送
UIKeyboardWillHideNotification //键盘隐藏之前发送
UIKeyboardDidHideNotification //键盘隐藏之后发送

 




原标题:UITextField属性

关键词:ie

ie
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

eBay刊登有哪几项特殊费用促销方式可选?:https://www.ikjzd.com/articles/91417
从亚马逊选品案例看亚马逊选品思路!:https://www.ikjzd.com/articles/91422
Amazon Business成功卖家案例教你如何掘金!:https://www.ikjzd.com/articles/91423
亚马逊运营指南——如何优化你的亚马逊产品页?:https://www.ikjzd.com/articles/91427
印尼电商独角兽Tokopedia尝试新零售?机遇与挑战并存:https://www.ikjzd.com/articles/91429
中国品牌,就是硬核!:https://www.ikjzd.com/articles/91436
三亚有哪些酒店值得入住?:https://www.vstour.cn/a/366173.html
零售晚报:丽人丽妆2023年扭亏为盈 玉容初、美壹堂等自有品牌增速超40% :https://www.kjdsnews.com/a/1836649.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流