zoukankan      html  css  js  c++  java
  • UITextField使用

    原文地址:http://quding0308.iteye.com/blog/1993447

    C代码  收藏代码
    1.     _textField.frame = CGRectMake(0, 0, 200, 50);  
    2.     _textField.delegate = self;  
    3.     _textField.text = str;  
    4.       
    5.     [_textField becomeFirstResponder];  
    6.       
    7.       
    8.     /* 
    9.      设置背景色、背景图片。设置了背景图片后,背景色设置无效 
    10.      如果background为nil,disabledBackground无效 
    11.      */  
    12.     _textField.background = [UIImage imageNamed:@"返回-按下"];  
    13.     _textField.disabledBackground = [UIImage imageNamed:@"返回-未激活"];  
    14. //    _textField.enabled = NO;  
    15.     _textField.backgroundColor = [UIColor blueColor];  
    16.     _textField.placeholder = @"输入文本…";  
    17.       
    18.     /* 
    19.      设置为YES时文本会自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动 
    20.      */  
    21.     _textField.adjustsFontSizeToFitWidth = YES;  
    22.     //设置自动缩小显示的最小字体大小,adjustsFontSizeToFitWidth为YES才会起作用  
    23.     _textField.minimumFontSize = 20;  
    24.     _textField.font = [UIFont systemFontOfSize:30.0f];  
    25.       
    26.     /* 
    27.      内容对齐方式 
    28.      内容的垂直对齐方式  UITextField继承自UIControl,此类中有一个属性contentVerticalAlignment 
    29.      */  
    30.     _textField.textAlignment = UITextAlignmentLeft;  
    31.     _textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;  
    32.       
    33.     /* 
    34.      typedef enum { 
    35.      UITextBorderStyleNone, 
    36.      UITextBorderStyleLine, 
    37.      UITextBorderStyleBezel, 
    38.      UITextBorderStyleRoundedRect 
    39.      } UITextBorderStyle; 
    40.      */  
    41.     _textField.borderStyle = UITextBorderStyleBezel;  
    42.   
    43.     /* 
    44.      每输入一个字符就变成点 用语密码输入 
    45.      */  
    46.     _textField.secureTextEntry = NO;  
    47.       
    48.     /* 
    49.      //输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容 
    50.      typedef enum { 
    51.      UITextFieldViewModeNever, 重不出现 
    52.      UITextFieldViewModeWhileEditing, 编辑时出现 
    53.      UITextFieldViewModeUnlessEditing, 除了编辑外都出现 
    54.      UITextFieldViewModeAlways  一直出现 
    55.      } UITextFieldViewMode; 
    56.      */  
    57.     _textField.clearButtonMode = UITextFieldViewModeWhileEditing;  
    58.       
    59.     /* 
    60.      开始编辑,清空数据 
    61.      */  
    62.     _textField.clearsOnBeginEditing = NO;  
    63.       
    64.     /* 
    65.      //是否纠错 
    66.      typedef enum { 
    67.      UITextAutocorrectionTypeDefault, 默认 
    68.      UITextAutocorrectionTypeNo,  不自动纠错 
    69.      UITextAutocorrectionTypeYes, 自动纠错 
    70.      } UITextAutocorrectionType; 
    71.      */  
    72.     _textField.autocorrectionType = UITextAutocorrectionTypeYes;  
    73.       
    74.     /* 
    75.      //首字母是否大写 
    76.      typedef enum { 
    77.      UITextAutocapitalizationTypeNone, 不自动大写 
    78.      UITextAutocapitalizationTypeWords, 单词首字母大写 
    79.      UITextAutocapitalizationTypeSentences, 句子的首字母大写 
    80.      UITextAutocapitalizationTypeAllCharacters, 所有字母都大写 
    81.      } UITextAutocapitalizationType; 
    82.      */  
    83.     _textField.autocapitalizationType = UITextAutocapitalizationTypeWords;  
    84.       
    85.     /* 
    86.      键盘 
    87.      typedef enum { 
    88.      UIKeyboardTypeDefault,      默认键盘,支持所有字符 
    89.      UIKeyboardTypeASCIICapable, 支持ASCII的默认键盘 
    90.      UIKeyboardTypeNumbersAndPunctuation, 标准电话键盘,支持+*#字符 
    91.      UIKeyboardTypeURL,            URL键盘,支持.com按钮 只支持URL字符 
    92.      UIKeyboardTypeNumberPad,             数字键盘 
    93.      UIKeyboardTypePhonePad,   电话键盘 
    94.      UIKeyboardTypeNamePhonePad,  电话键盘,也支持输入人名 
    95.      UIKeyboardTypeEmailAddress,  用于输入电子 邮件地址的键盘 
    96.      UIKeyboardTypeDecimalPad,    数字键盘 有数字和小数点 
    97.      UIKeyboardTypeTwitter,       优化的键盘,方便输入@、#字符 
    98.      UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, 
    99.      } UIKeyboardType; 
    100.      */  
    101.     _textField.keyboardType = UIKeyboardTypeDefault;  
    102.       
    103.     /* 
    104.      //return键变成什么键 
    105.      typedef enum { 
    106.      UIReturnKeyDefault, 默认 灰色按钮,标有Return 
    107.      UIReturnKeyGo,     标有Go的蓝色按钮 
    108.      UIReturnKeyGoogle,标有Google的蓝色按钮,用语搜索 
    109.      UIReturnKeyJoin,标有Join的蓝色按钮 
    110.      UIReturnKeyNext,标有Next的蓝色按钮 
    111.      UIReturnKeyRoute,标有Route的蓝色按钮 
    112.      UIReturnKeySearch,标有Search的蓝色按钮 
    113.      UIReturnKeySend,标有Send的蓝色按钮 
    114.      UIReturnKeyYahoo,标有Yahoo的蓝色按钮 
    115.      UIReturnKeyYahoo,标有Yahoo的蓝色按钮 
    116.      UIReturnKeyEmergencyCall, 紧急呼叫按钮 
    117.      } UIReturnKeyType; 
    118.      */  
    119.     _textField.returnKeyType = UIReturnKeyDone;  
    120.       
    121.     /* 
    122.      //键盘外观 
    123.      typedef enum { 
    124.      UIKeyboardAppearanceDefault, 默认外观,浅灰色 
    125.      UIKeyboardAppearanceDark,   深灰 石墨色 
    126.      UIKeyboardAppearanceLight 浅灰色 
    127.      } UIReturnKeyType; 
    128.      */  
    129.     _textField.keyboardAppearance=UIKeyboardAppearanceDefault;  
    130.       
    131.     /* 
    132.      设置左右的两个view 
    133.      */  
    134. //    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_right"]];  
    135. //    imgView.frame = CGRectMake(0, 0, 20, 20);  
    136. //    _textField.rightView = imgView;  
    137. //    _textField.rightViewMode = UITextFieldViewModeAlways;   // 同上  
    138.       
    139.     UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_left"]];  
    140.     imgView.frame = CGRectMake(0, 0, 20, 20);  
    141.     _textField.leftView = imgView;  
    142.     _textField.leftViewMode = UITextFieldViewModeAlways;   // 同上  
    143.       
    144.       
    145.     /* 
    146.      重写绘制行为 
    147.      除了UITextField对象的风格选项,你还可以定制化UITextField对象,为他添加许多不同的重写方法,来改变文本字段的显示行为。这些方法都会返回一个CGRect结构,制定了文本字段每个部件的边界范围。以下方法都可以重写。 
    148.       
    149.      – textRectForBounds:     //重写来重置文字区域 
    150.      – drawTextInRect:         //改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了. 
    151.      – placeholderRectForBounds:  //重写来重置占位符区域 
    152.      – drawPlaceholderInRect:  //重写改变绘制占位符属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了. 
    153.      – borderRectForBounds:  //重写来重置边缘区域 
    154.      – editingRectForBounds:  //重写来重置编辑区域 
    155.      – clearButtonRectForBounds:  //重写来重置clearButton位置,改变size可能导致button的图片失真 
    156.      – leftViewRectForBounds: 
    157.      – rightViewRectForBounds: 
    158.      */  

     

  • 相关阅读:
    如何在域和域之间建立信任域?关键是配置域和域之间的DNS服务器
    Client Recevier 命令安装 AllUsers=1
    在XD 4.0 设置Policy
    更改linux系统中键盘设置
    如何在DNS中添加另一DNS
    CMD命令
    KMS激活OS(系统)
    谁抢了我的IP!!!~
    关于域证书的发布CA和CRL的内容 (Windows 2008 Server R2 SP1)
    XenServer假死状态
  • 原文地址:https://www.cnblogs.com/aggie/p/4608445.html
Copyright © 2011-2022 走看看