关于UItextField的LeftView属性
leftView属性赋值时 如果给两个textfield 同时设置这个属性 不能是同一个 View 如果是同一个View 这个页面就不能跳转
UIView *leftSpaceView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, leftViewW, textFieldH)];
leftSpaceView.backgroundColor = [UIColor whiteColor];
UIView *leftSpaceViewSecond = [[UIView alloc] initWithFrame:CGRectMake(0, 0, leftViewW, textFieldH)];
leftSpaceView.backgroundColor = [UIColor whiteColor];
UITextField *phoneNum = [[UITextField alloc] initWithFrame:CGRectMake(spaceBetweenX, 65, KScreenW - spaceBetweenX*2, textFieldH)];
phoneNum.tag = -15;
phoneNum.leftView = leftSpaceView;
phoneNum.leftViewMode = UITextFieldViewModeAlways;
phoneNum.layer.borderWidth = 1.0;
phoneNum.layer.borderColor = [UIColor colorWithHexString:@"#dadada" withAlpha:1].CGColor;
phoneNum.placeholder = @"已注册手机号";
[self.view addSubview:phoneNum];
UITextField *newCode = [[UITextField alloc] initWithFrame:CGRectMake(spaceBetweenX, CGRectGetMaxY(phoneNum.frame) + 25, KScreenW - spaceBetweenX*2 - phoneNum.bounds.size.width*1/3 - 10, textFieldH)];
newCode.backgroundColor = [UIColor clearColor];
newCode.layer.borderColor = [UIColor colorWithHexString:@"#dadada" withAlpha:1].CGColor;
newCode.layer.borderWidth = 1.0f;
newCode.leftView = leftSpaceViewSecond;
newCode.leftViewMode = UITextFieldViewModeAlways;
newCode.tag = -16;
newCode.placeholder = @"请输入短信验证码";
[self.view addSubview:newCode];
placeholder的字体颜色、大小
NSAttributedString *one = [[NSAttributedString alloc] initWithString:@" 官方自带" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:30]}];
tureText.attributedPlaceholder = one;
UITextField中文输入法输入时对字符长度的限制 想限制几位就写几
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if ([textField isEqual:self.verifyField]) {
if (range.location>=3)
return NO;
}
}
return YES;
}