UITextField

-----------------UITextField--------------

  UITextField:输入框  作用:输入内容

    创建输入框

    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 160, 40)];

    textField.center = CGPointMake(160, 120);    

    类型

    textField. borderStyle = UITextBorderStyleRoundedRect;    

    设置背景色

    textField.backgroundColor = [UIColor grayColor];    

    显示

    [self.view addSubview:textField];

---------------键盘弹回-------------

  输入框: 知道输入的内容什么时候输完,不知道键盘什么时候弹回。     

     当前界面:知道键盘什么时候弹回,不知道内容什么时候输完     

     当内容输完时,怎么将键盘弹回?     

     通过代理     

     1.在输入框的类里面写协议,协议里面有控制键盘回收等功能的方法     

     2.让当前类引用协议     

     3.将当前类设置成输入框的代理类     

     4.在当前类里面写协议的相关方法的具体实现    

  ZKViewController ()<UITextFieldDelegate>

  点解retun键执行的方法,作用:回收键盘

  -(BOOL)textFieldShouldReturn:(UITextField *)textField{

      //第一响应项  :当前正在响应(正在与用户进行交互)的对象

      //键盘回收的做法:取消第一响应项

      [textField resignFirstResponder];

      //变成第一响应项(不常使用)

      //[textField becomeFirstResponder];

      return YES;}

 -----UITextField属性------- 

  设置中心

      textField. center = CGPointMake(160, 120);

    设置背景颜色

      textField.backgroundColor = [UIColor grayColor];

    设置样式

      textField. borderStyle = UITextBorderStyleRoundedRect;

 

    1、输入前默认提示文字

    textField. placeholder = @"请输入用户名";

    passField.placeholder = @"请输入密码";

  2、添加清除按钮               总显示

    textField.clearButtonMode = UITextFieldViewModeAlways;

    passField.clearButtonMode = UITextFieldViewModeAlways;

    3、安全输入

    passField. secureTextEntry = YES; 

 4、设置背景图

    //要想自定义背景图,先要将输入框的样式设置成非RoundRect

    textField.borderStyle = UITextBorderStyleLine;

    textField.background = [UIImage imageNamed:@"back"];

    5、限制return键的使用,当输入框没有内容的时候,return键不可用

    textField. enablesReturnKeyAutomatically = YES;

    passField. enablesReturnKeyAutomatically = YES;

    6、数字键盘

    passField. keyboardType = UIKeyboardTypeNumberPad;

    7、设置左视图 和右视图

    textField. leftView = imageViewLeft;-----(imageViewLeft是一个图片视图)

  textField. rightView = imageViewRight;-----(imageViewRight是一个图片视图)

    //设置显示方式

注意:要想让左视图显示,必须设置显示方式

    textField.leftViewMode = UITextFieldViewModeAlways;

    textField.rightViewMode = UITextFieldViewModeAlways;

  11.去掉开头字母大写提示

    textField. autocapitalizationType = UITextAutocapitalizationTypeNone;

  12.去掉纠错

    textField. autocorrectionType = UITextAutocorrectionTypeNo;

    13.自动缩小输入的文字,进行自适应显示

    textField. adjustsFontSizeToFitWidth = YES;

    //缩小到的最小尺寸号

    textField. minimumFontSize = 5;

  14.调整文字的位置

    14.1上下(靠下面显示)

    thirdField. contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;    

    14.2 水平(靠右边显示)

    thirdField.textAlignment = NSTextAlignmentRight;    

    15.文字的大小

    thirdField. font = [UIFont systemFontOfSize:20];

所有的控件都可以根据tag值来区分

 

posted on 2014-12-30 11:24  溜逗~~  阅读(146)  评论(0编辑  收藏  举报

导航