UITextField *_tfInput = [[UITextField alloc]init];
_tfInput.tintColor = [UIColor whiteColor];
_tfInput.clearButtonMode=UITextFieldViewModeWhileEditing;
_tfInput.textColor = [UIColor whiteColor];
[_tfInput setKeyboardType:UIKeyboardTypeDefault];
//设置Placeholder 颜色 内容 字体大小
_tfInput.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"输入约跑主题" attributes:@{NSForegroundColorAttributeName:[�UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:14.f]}];
[self.contentView addSubview:_tfInput];
补充:更改UITextField右边按钮的图片
MBTextField 继承 UITextField
@implementation MBTextField
- (instancetype)init
{
self = [super init];
if (self) {
// [self setBackgroundColor:[UIColor redColor]];
[self setTextColor:[UISystemColor getSystemWhite]];
[self setTintColor:[UIColor whiteColor]];
[self setKeyboardType:UIKeyboardTypeNumberPad];
[self setClearButtonMode:UITextFieldViewModeWhileEditing];
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
[self setClearButtonColor];
}
- (UIButton *)getClearButton{
for(UIView *v in self.subviews)
{
if([v isKindOfClass:[UIButton class]])
{
UIButton *clearButton = (UIButton *) v;
return clearButton;
}
}
return nil;
}
- (void)setClearButtonColor{
UIButton *clearButton = [self getClearButton];
if(clearButton){
[clearButton setImage:[UIImage imageNamed:@"login_del"] forState:UIControlStateNormal];
}
}