UITextField基本用法

//TextField 是UIControl的子类, UIControl又是UIView的子类, 所以也是视图, 只不过比UIView多了两个功能:1 文字显示 2 文本编辑 也是分为四步:1 创建对象 2 配置属性 3 添加到父视图 4 释放所有权
- (void)creatTextField
{
    //创建对象
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(160 - 75, 120, 150, 40)];
    //设置属性
    
    textField.backgroundColor = [UIColor whiteColor];
    //1 设置textField的样式 UITextBorderStyleRoundedRect圆角矩形
    textField.borderStyle = UITextBorderStyleRoundedRect;
    //2 设置textField显示的提示文字, 但是不作为文本的内容
    textField.placeholder = @"用户名/邮箱";
    //3 设置textField开始显示的文字
    textField.text = @"username";
    //4 设置文本的颜色
    textField.textColor = [UIColor redColor];
    //5 设置文本的对齐方式
    textField.textAlignment = NSTextAlignmentLeft;
    //6 设置文本的字体
    textField.font = [UIFont fontWithName:@"Courier New" size:20];
    //7 设置输入框是否可编辑
    textField.enabled = YES;
    //8 设置当开始编辑时, 是否清楚输入框的内容
    textField.clearsOnBeginEditing = YES;
    //9 设置密码模式, 输入框中的内容是否以点的形式显示
    textField.secureTextEntry = YES;
    //10 设置弹出键盘的样式
//    textField.keyboardType = UIKeyboardTypeNumberPad;
    //11 键盘右下角显示的样式
    textField.returnKeyType = UIReturnKeyDone;
    //12 代理 使用步骤
    //1> 设置代理
    //2> 服从协议
    //3> 实现协议中的方法
    textField.delegate = self;//self是当前类对象(CCLAppDelegate)
    //13 inputView
    UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 300, 320, 40)];
    inputView.backgroundColor = [UIColor whiteColor];
//    textField.inputView = inputView;
    //14
    textField.inputAccessoryView = inputView;
    
    //添加到父视图
    [_bgView addSubview:textField];
    //释放
    [textField release];
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值