UITextField常见用法

//实例变量和全局变量的区别

//1、定义位置有区别:全局变量定义在方法的外部,实例变量写在接口文件或者延展中的大括号之内

//2、生命周期:全局变量生命周期和应用程序生命周期相同,实例变量的生命周期依托于对象,有对象才会有空间,生命周期开始,对象销毁,生命周期结束。

//3、可见度:全局变量全局都可以访问。实例变量,实例方法可以用。

 

//UITextField是iOS中,用来输入文字的控件,比UILabel多了文字编辑的功能,是UIControl的子类,而UIControl是UIView的子类

    //UITextField 使用 和UILabel很相似

    //1、创建UITextField

    //2、配置属性

    //3、添加到父视图

    //4、release

    

    UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(80 , 50 , 100, 30)];

    textField1.backgroundColor = [UIColor blueColor];

    [contentView addSubview:textField1];

    [textField1 release];

    //1、创建视图

    _textField = [[UITextField alloc] initWithFrame:CGRectMake(20 , 100 , 200 , 40)];

    //2、配置属性

    //背景色

    _textField.backgroundColor = [UIColor grayColor];

    //配置输入框的样式

    _textField.borderStyle = UITextBorderStyleRoundedRect;

    //输入框的提示文字(当输入框中没有内容时显示)(占位符)

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

    //字体(系统默认17)

    _textField.font = [UIFont systemFontOfSize:23];

    //显示文字(用户默认需要用到 +86)

    _textField.text = @"dfghjklfrgj";

//    NSLog(@"%@" , _textField.text);

//    _textField.textColor = [UIColor brownColor];

//    _textField.textAlignment = NSTextAlignmentCenter;

    

    //文字显示成密码的输入状态

//    _textField.secureTextEntry = YES;

    //键盘类型

    _textField.keyboardType = UIKeyboardTypeNumberPad;

    //是否允许编辑( 默认YES)

//    _textField.enabled = YES;

    //键盘上return键的类型

//    _textField.returnKeyType = UIReturnKeyJoin;

    //开始编辑的时候,输入框的内容清空

    _textField.clearsOnBeginEditing = YES;

    

    //自定义弹出设置键盘(只需要高度)

    UIView *intputView = [[UIView alloc] initWithFrame:CGRectMake(100 , 100 , 100 , 150)];

    intputView.backgroundColor = [UIColor yellowColor];

    _textField.inputView = intputView;

 

    

    _textField.delegate = self;

   

    

    //3、添加父视图上面

    [contentView addSubview:_textField];

    //4、release

    [_textField release];

 

posted @ 2015-05-21 18:00  fengkuangIT  阅读(261)  评论(0编辑  收藏  举报