设置UITextField的内容
1.使用KVC的方式设置placeholder的字体大小、颜色,比较简单的方式,但不是人人都会的
-(UITextField *)textFild{
if (!_textFild) {
CGFloat x = CGRectGetMaxX(_nameLabel.frame) + 8;
_textFild = [[UITextField alloc]initWithFrame:CGRectMake(x, 0, kScreenWidth - x - 20, PlaceOrderCellH)];
_textFild.font = [UIFont systemFontOfSize:14];
_textFild.textColor = [UIColor colorWithHexString:@"#e3e3e3"];
_textFild.placeholder = @"请输入充值帐号";
// 设置placeholder的颜色和字体大小
[_textFild setValue:[UIColor colorWithHexString:@"#e3e3e3"] forKeyPath:@"_placeholderLabel.textColor"];
[_textFild setValue:[UIFont boldSystemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];
_textFild.tag = 18;
_textFild.returnKeyType = UIReturnKeyDone;
[_textFild addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
_textFild.delegate = self;
}
return _textFild;
}
- placehoder的位置
众所周知,UITextField是有leftView和rightView的,可以通过设置器左右视图来调整placehoder的位置,这里有个问题要注意leftViewMode一定要设置成UITextFieldViewModeAlways,否则,leftView设置就会失败
-(UITextField *)textFild{
if (!_textFild) {
CGFloat x = CGRectGetMaxX(_nameLabel.frame) + 8;
_textFild = [[UITextField alloc]initWithFrame:CGRectMake(x, 0, kScreenWidth - x - 20, PlaceOrderCellH)];
_textField.leftViewMode = UITextFieldViewModeAlways;
_textField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 16, 48)];
_textFild.delegate = self;
}
return _textFild;
}
网友评论