码迷,mamicode.com
首页 > 其他好文 > 详细

关于UITextField

时间:2015-09-26 00:32:17      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

 一: 创建:

   UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(50, 50, 200, 50)];

 二: UITextField的一些属性

   (1) 颜色:tf.backgroundColor = [UIColor yellowColor];

   (2) 文本:(可读可写): tf.text = @"dve";

   (3) 占位:tf.placeholder = @"请输入用户名";

   (4) 文本颜色:tf.textColor = [UIColor blueColor];

   (5) 文本位置:tf.textAlignment = NSTextAlignmentCenter;

   (6) 文本字体:tf.font = [UIFont fontWithName:@"HelveticaBold" size:20];

   (7) 输入控制  控制能否输入 (默认是YES 可以输入):tf.enabled = NO;

   (8) 是否清除上次的输入:tf.clearsOnBeginEditing = YES;

   (9) 安全输入(密码模式):tf.secureTextEntry = YES;

   (10) 键盘类型:tf.keyboardType = UIKeyboardTypeNumberPad;

   (11) 改变return键返回的内容:tf.returnKeyType = UIReturnKeyDone;

   (12) 外观控制 边框:tf.borderStyle = 3;

   (13) 清除类型:tf.clearButtonMode = UITextFieldViewModeAlways;

   (14) 左视图:tf.leftViewMode = UITextFieldViewModeWhileEditing;

三:用UITextField、UILabel和UIButton简单实现下面的界面

技术分享

实现代码: 

// 添加用户名label

    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(30, 100, 80, 30)];

    label1.text = @"用户名";

    label1.textColor = [UIColor blackColor];

    [_window addSubview:label1];

    

    // 添加用户名textfield

    UITextField *text1 = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label1.frame) + 20, CGRectGetMinY(label1.frame), 200, CGRectGetHeight(label1.frame))];

    //text1.backgroundColor = [UIColor blueColor];

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

    text1.borderStyle = 3;

    text1.clearButtonMode = UITextFieldViewModeWhileEditing;

    [_window addSubview:text1];

    

    // 添加密码label

    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(label1.frame),CGRectGetMaxY(label1.frame) + 30, CGRectGetWidth(label1.frame), CGRectGetHeight(label1.frame))];

    label2.text = @"密码";

    label2.textColor = [UIColor blackColor];

    [_window addSubview:label2];

    

    // 添加密码text

    UITextField *text2 = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(text1.frame), CGRectGetMaxY(text1.frame) + 30, CGRectGetWidth(text1.frame), CGRectGetHeight(text1.frame))];

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

    text2.secureTextEntry = YES;

    text2.borderStyle = 3;

    text2.keyboardTypeUIKeyboardTypeNumberPad;

    text2.clearButtonMode = UITextFieldViewModeWhileEditing;

    [_window addSubview:text2];

 

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];

    button1.frame = CGRectMake(30, CGRectGetMaxY(label2.frame)+30, 90, 30);

    [button1 setTitle:@"登录" forState:UIControlStateNormal];

    [_window addSubview:button1];

    

    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];

    button2.frame = CGRectMake(CGRectGetMaxX(button1.frame)+15, CGRectGetMaxY(label2.frame)+30, 90, 30);

    [button2 setTitle:@"修改密码" forState:UIControlStateNormal];

    [_window addSubview:button2];

    

    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeSystem];

    button3.frame = CGRectMake(CGRectGetMaxX(button2.frame)+15, CGRectGetMaxY(label2.frame)+30, 90, 30);

    [button3 setTitle:@"注册" forState:UIControlStateNormal];

    [_window addSubview:button3];

关于UITextField

标签:

原文地址:http://www.cnblogs.com/cityingma/p/4839733.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!