您的位置:首页 > 产品设计 > UI/UE

UI 03 UITextField

2015-08-03 08:50 417 查看
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{
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: