UITextField *txtAccount = [[UITextField alloc] initWithFrame:CGRectMake(10, 10,300, 30)]; 字体
// 设置委托 spa
[txtAccount setDelegate:self]; orm
// 设置占位符 string
[txtAccount setPlaceholder:@"帐号"]; it
// 设置颜色 请求
[txtAccount setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; 方法
// 设置字体 样式
[txtAccount setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"]; di
// 设置文本对齐 键盘
[txtAccount setTextAlignment:NSTextAlignmentLeft];
// 设置样式
[txtAccount setBorderStyle:UITextBorderStyleRoundedRect];
// 加入view中
[self.view addSubview: txtAccount];
[txtAccount release];
// 设置输入框,是否能够被修改
// NO-将没法修改,不出现键盘
// YES-能够修改,默认值
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return YES;
}
// 当点击键盘的返回键(右下角)时,执行该方法。
// 通常用来隐藏键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
if (txtAccount == textField) {
[txtAccount resignFirstResponder];
}
return YES;
}
// 当输入框得到焦点时,执行该方法。
- (void)textFieldDidBeginEditing:(UITextField *)textField{
NSLog(@"textFieldDidBeginEditing");
}
// 指定是否容许文本字段结束编辑,容许的话,文本字段会失去first responder
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
NSLog(@"textFieldDidEndEditing");
}
// 指明是否容许根据用户请求清除内容
- (BOOL)textFieldShouldClear:(UITextField *)textField{
NSLog(@"textFieldDidEndEditing");
return YES;
}
// 文本框的文本,是否能被修改
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
return YES;
}