依然,先看张图放松下
我们自以为知之甚多的事物的背后,无不潜伏着等量的未知因素。所谓理解,通常不过是误解的总合。by 村上春树
- 下面总结,目前为止,我还记得起的误解总和!以后想起来的,一块总结在此!
1.设置UITextField的输入长度
UITextField *phoneTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 20, MainScreenWidth-30, 44)];
phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
phoneTextField.placeholder = @"输入手机号";
phoneTextField.textAlignment = NSTextAlignmentLeft;
phoneTextField.font = [UIFont systemFontOfSize:15];
self.phoneTextField = phoneTextField;
phoneTextField.delegate = self;
[self addSubview:phoneTextField];
[phoneTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
下面这个才是关键
- (void)textFieldDidChange:(UITextField *)textField
{
if (textField == self.phoneTextField) {
if (textField.text.length > 11) {
textField.text = [textField.text substringToIndex:11];
}
}
}
设置的效果就是---限制输入11位,之后就按啥都不管用了
2.设置UITextField的输入模式,明文,还是密文
self.phoneTextField.secureTextEntry = NO;
3.设置UITextField的placeHolder,占位文字属性
//设置占位文字的颜色
[self.phoneTextField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
//设置输入文字的颜色
self.phoneTextField.textColor = [UIColor redColor];
//设置光标颜色,不多用
[self.phoneTextField setTintColor:[UIColor whiteColor]];
4.背景图片设置,也不是用的很多
//先要去除边框样式(类似UIButtonCustom)
self.phoneTextField.borderStyle = UITextBorderStyleNone;
self.phoneTextField .background = [UIImage imageNamed:@"phoneNum.png"];
5.设置再次编辑是否清空
self.phoneTextField .clearsOnBeginEditing = NO;
6.设置输入框内容的字体样式和大小
self.phoneTextField.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15]
;
7.textAlignment:内容对齐方式
//与UILabel一样,就不在详细写了
self.phoneTextField.textAlignment = UITextAlignmentLeft;
8.设置边框样式
self.phoneTextField.borderStyle = UITextBorderStyleRoundedRect;
//无任何边框
UITextBorderStyleNone ;
//黑色线框
UITextBorderStyleLine ;
//边线+阴影
UITextBorderStyleBezel ;
//浅色带圆弧线框
UITextBorderStyleRoundedRect;
9.设置编辑时,可全部删除,x号按钮
self.phoneTextField.clearButtonMode = UITextFieldViewModeAlways;
10.这个设置我一般不会用到,系统的太丑了
self.phoneTextField.returnKeyType =UIReturnKeyDone;
需要设置这儿的自行百度吧,地址就不贴了
11 .自定义键盘属性(inputView)---我还没用到
//自定义键盘,将原有的键盘隐藏,显示当前自定义视图
UIView *keyBoardContent = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 100)];
keyBoardContent.backgroundColor = [UIColor darkGrayColor];
ettxf.inputView = keyBoardContent;
同上,以后用到再来总结,看看就好!
12.自定义辅助键盘视图(inputAccessoryView),这个用的还是挺多的,有时候需要在键盘上绑定一个完成按钮,在输入完成后,键盘回收
UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 80)];
subView.backgroundColor = [UIColor greenColor];
ettxf.inputAccessoryView = subView;
东西不算多,还有啥常用的,想起来,在添!