UI 03 UITextField

UITextField 继承于 UIControl .
特殊的技能是可以输入.

// 输入框
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 50, 200, 40)];
    textField.backgroundColor = [UIColor whiteColor];
    [self.window addSubview:textField];
    [textField release];

    textField.layer.borderWidth = 1;
    textField.layer.cornerRadius = 10;

    // 初始文本
    //textField.text = @"贱男";
    textField.textColor = [UIColor purpleColor];

    // 占位文本
    textField.placeholder = @"请输入姓名";

    textField.textAlignment = NSTextAlignmentCenter;
    textField.keyboardType = UIKeyboardTypeDefault;

    // return 按钮切换样式
    textField.returnKeyType = UIReturnKeyDone;
    textField.clearsOnBeginEditing = YES;
    //textField.secureTextEntry = YES;

    // 清除按钮的样式
    textField.clearButtonMode =  UITextFieldViewModeAlways;

    // 创建一个view
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 20, 20)];
    view.backgroundColor = [UIColor orangeColor];

    // 弹出一个自定义的视图,默认是键盘
   textField.inputView = view;

    // 给键盘添加一个辅助视图.
    textField.inputAccessoryView = view;


    // 给textfield设置代理人.
    textField.delegate = self;


    // 点击Return 按钮,回收键盘.(协议)

下面的方法是:

// 实现协议方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSLog(@"测试return按钮");
    NSLog(@"%@",textField.text);

    // 这句话是回收return键盘
    [textField resignFirstResponder];
    return YES; 
}


- (BOOL)textFieldShouldClear:(UITextField *)textField{   
    NSLog(@"测试清除按钮");
    return YES;
}

// UITextField 继承于UIControl 所以也有这个点击方法.
- (void)click:(UITextField *)textField{
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值