UITextField

    // 初始化textfield并设置位置及大小

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

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

    //text.borderStyle = UITextBorderStyleRoundedRect;

    text.borderStyle = UITextBorderStyleBezel;

    // typedef enum{

//    UITextBorderStyleBezel,

//    UITextBorderStyleLine,

//    UITextBorderStyleNone,

    //UITextBorderStyleRoundedRect,

    // }UITextBorderStyle;

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

    text.backgroundColor = [UIColor redColor];

    // 设置背景

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

    // 设置背景

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

    // 设置输入框没有内容时,水印提示,提示内容为password

    text.placeholder = @"password";

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

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

    // 设置字体颜色

    text.textColor = [UIColor redColor];

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

    text.clearButtonMode = UITextFieldViewModeAlways;

    // typedef enum{

//    UITextFieldViewModeNever  从不出现

//    UITextFieldViewModeWhileEditing   编辑时出现

//    UITextFieldViewModeUnlessEditing    除了编辑外都出现

//    UITextFieldViewModeAlways    一直出现

    // }UITextFieldViewMode;

    // 输入框中一开始就有的文字

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

    // 每输入一个字符就变成点,用于密码输入

    text.secureTextEntry = YES;

    // 是否纠错

    text.autocorrectionType = UITextAutocorrectionTypeNo;

    // typedef enum{

//    UITextAutocorrectionTypeDefault   默认

//    UITextAutocorrectionTypeNo   不自动纠错

    // }UITextAuocorrectiontype;

    // 再次编辑就清空

    text.clearsOnBeginEditing = YES;

    // 内容对齐方式

   // text.textAlignment = UITextAlignmentLeft;

    // 内容的垂直对齐方式,UITextfield 继承自UIControl ,此类中有一个属性contentVerticalAlignmet

    text.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

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

    text.adjustsFontSizeToFitWidth = YES;

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

    text.minimumFontSize = 20;

    // 设置键盘的样式

    text.keyboardType = UIKeyboardTypeNumberPad;

    // typedef enum{

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

//    UIKeyboardTypeASCIICapable   支持ASCII的默认键盘

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

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

//    UIKeyboardTypeNumberPad    数字键盘

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

//    UIKeyboardTypePhonePad    电话键盘

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

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

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

//    UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable

    // } UIKeyboardType;

    // 首字母是否大写

    text.autocapitalizationType = UITextAutocapitalizationTypeNone;

    // typedef enum{

//    UITextAutocapitalizationTypeNone  不自动大写

//    UITextAutocapitalizationTypeSentences   句子的首字母大写

//    UITextAutocapitalizationTypeWords    单词首字母大写

//    UITextAutocapitalizationTypeAllCharacters     所有首字母大写

    // } UITextAutocapotalizationType;

    // return 键变成什么键

    text.returnKeyType = UIReturnKeyDone;

    // typedef enum{

//    UIReturnKeyDefault   默认灰色按钮 标有return

//    UIReturnKeyGo    标有go 的蓝色按钮

//    UIReturnKeyEmergencyCall    紧急呼叫按钮

//    UIReturnKeyGoogle   标有google 的蓝色按钮 用于搜索

//    UIReturnKeyJoin   标有join的蓝色按钮

//    UIReturnKeyNext  标有next的蓝色按钮

//    UIReturnKeyRoute  标有route的蓝色按钮

//    UIReturnKeySearch  标有search 的蓝色按钮

//    UIReturnKeySend   标有send的蓝色按钮

//    UIReturnKeyYahoo   标有Yahoo 的蓝色按钮

    // }UIReturnKeyType;

    // 键盘外观

    text.keyboardAppearance = UIKeyboardAppearanceDefault;

    // typedef enum{

//    UIKeyboardAppearanceDefault   默认外观 浅灰色

//    UIKeyboardAppearanceAlert   深灰 石墨色

//    UIKeyboardAppearanceDark

//    UIKeyboardAppearanceLight

    // } UIReturnKeyType;

    // 设置代理 用于实现协议

    text.delegate = self;

    // 把text添加到视图中

    [self.view addSubview:text];

    // 最右侧加图片是以下代码  左侧类似

    UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"right.png"]];

    text.rightView = image;

    text.rightViewMode = UITextFieldViewModeAlways;

    // typedef enum{

   // UITextFieldViewModeAlways

    //UITextFieldViewModeNever

    //UITextFieldViewModeUnlessEditing

    //UITextFieldViewModeWhileEditing

    //}UITextFieldViewMode;

    // 按return键键盘往下收 becomeFirstResponder 类要采用UITextFieldDelegate协议

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

//    - (BOOL)textFieldShouldReturn:(UITextfield *)textField

//    {

//        [text resignFirstResponder]; // 主要是[receiver resignFirstResponder]在哪调用就能把receiver对应的键盘往下收

//        return YES;

//    }

    

    

    

    

    

    

    

    

    

 

    

    

    [self.view addSubview:text];

 

posted @ 2015-05-06 15:55  certify  阅读(135)  评论(0编辑  收藏  举报