UITextField的整理

   UITextField:

UITextField是常用的输入控件,控制文本输入和显示的控件,允许用户编辑(输入)


1.初始化textfield并设置位置及大小

  UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)];

 

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

  text.borderStyle = UITextBorderStyleRoundedRect;

边框样式

typedef enum {

    UITextBorderStyleNone, 

    UITextBorderStyleLine,

    UITextBorderStyleBezel,

    UITextBorderStyleRoundedRect  

  } UITextBorderStyle;

  

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

   text.backgroundColor = [UIColor whiteColor];

 

4.设置背景

  text.background = [UIImage imageNamed:@"dd.png"];

 

5.设置背景 

  text.disabledBackground = [UIImage imageNamed:@"cc.png"];


6.当输入框没有内容时,水印提示 提示内容为password

  text.placeholder = @"password";

 

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

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

 

8.设置字体颜色

  text.textColor = [UIColor redColor];

 

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

  text.clearButtonMode = UITextFieldViewModeAlways;

typedef enum {

    UITextFieldViewModeNever,  重不出现

    UITextFieldViewModeWhileEditing, 编辑时出现

    UITextFieldViewModeUnlessEditing,  除了编辑外都出现

    UITextFieldViewModeAlways   一直出现

} UITextFieldViewMode;

 

10.每输入一个字符就变成点 用语密码输入

  text.secureTextEntry = YES;

 

11.是否纠错

  text.autocorrectionType = UITextAutocorrectionTypeNo;

 

typedef enum {

    UITextAutocorrectionTypeDefault, 默认

    UITextAutocorrectionTypeNo,   不自动纠错

    UITextAutocorrectionTypeYes,  自动纠错

} UITextAutocorrectionType;


12.再次编辑就清空

  text.clearsOnBeginEditing = YES; 

 

13.内容对齐方式

  text.textAlignment = UITextAlignmentLeft;

 

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

  text.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

 

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

  textFied.adjustsFontSizeToFitWidth = YES;

 

16.设置自动缩小显示的最小字体大小

  text.minimumFontSize = 20;


17.设置键盘的样式

  text.keyboardType = UIKeyboardTypeNumberPad;

 

typedef enum {

    UIKeyboardTypeDefault,       默认键盘,支持所有字符         

    UIKeyboardTypeASCIICapable,  支持ASCII的默认键盘

    UIKeyboardTypeNumbersAndPunctuation,  标准电话键盘,支持+*#字符

    UIKeyboardTypeURL,            URL键盘,支持.com按钮 只支持URL字符

UIKeyboardTypeNumberPad,              数字键盘

UIKeyboardTypePhonePad,     电话键盘

    UIKeyboardTypeNamePhonePad,   电话键盘,也支持输入人名

UIKeyboardTypeEmailAddress,   用于输入电子 邮件地址的键盘     

UIKeyboardTypeDecimalPad,     数字键盘 有数字和小数点

    UIKeyboardTypeTwitter,        优化的键盘,方便输入@#字符

    

} UIKeyboardType;

 

18.首字母是否大写

  text.autocapitalizationType = UITextAutocapitalizationTypeNone;

 

typedef enum {

    UITextAutocapitalizationTypeNone, 不自动大写

    UITextAutocapitalizationTypeWords,  单词首字母大写

    UITextAutocapitalizationTypeSentences,  句子的首字母大写

    UITextAutocapitalizationTypeAllCharacters, 所有字母都大写

} UITextAutocapitalizationType;

 

19.return键变成什么键

  text.returnKeyType =UIReturnKeyDone;

 

typedef enum {

    UIReturnKeyDefault, 默认 灰色按钮,标有Return

    UIReturnKeyGo,      标有Go的蓝色按钮

    UIReturnKeyGoogle,标有Google的蓝色按钮,用语搜索

    UIReturnKeyJoin,标有Join的蓝色按钮

    UIReturnKeyNext,标有Next的蓝色按钮

    UIReturnKeyRoute,标有Route的蓝色按钮

    UIReturnKeySearch,标有Search的蓝色按钮

    UIReturnKeySend,标有Send的蓝色按钮

    UIReturnKeyYahoo,标有Yahoo的蓝色按钮

UIReturnKeyEmergencyCall, 紧急呼叫按钮

} UIReturnKeyType;

 

20.键盘外观

textView.keyboardAppearance=UIKeyboardAppearanceDefault

typedef enum {

UIKeyboardAppearanceDefault 默认外观,浅灰色

UIKeyboardAppearanceAlert     深灰 石墨色

 

} UIReturnKeyType;

 



UIAlertview:

UIAlertview视图为用户显示提示信息,要求用户确认某个决定,从用户那里获得一些信息


//实例化UIAlertView,并指定标题、信息、和按钮

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@“My Title” message:@“This is message"delegate:nil cancelButtonTitle:@“Cancel" otherButtonTitles:@“Ok”,@“other”,nil];


//显示

[aleret show]; 

//也可以设置UIAlertView的样式


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值