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

UI 03 UITextField

时间:2015-08-03 10:24:21      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

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{
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

UI 03 UITextField

标签:

原文地址:http://blog.csdn.net/gao_zi/article/details/47251071

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