修改为白色:
self.userNameTextField.tintColor = [UIColor whiteColor];
修改clearButton的颜色,还是用最朴素的方法比较靠谱。
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"clear_button.png"] forState:UIControlStateNormal];
[button setFrame:CGRectMake(0.0f, 0.0f, 15.0f, 15.0f)];
theTextField.rightView = button;
theTextField.rightViewMode = UITextFieldViewModeWhileEditing;
也有通过UIButton *btnClear = [textField valueForKey:@"_clearButton"];
获取按钮
但是iOS11上好像并没有效果。
UIButton *btnClear = [textField valueForKey:@"_clearButton"];
UIImage * img = [btnClear imageForState:UIControlStateNormal];
if (img) {
UIImage * renderingModeImage = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[btnClear setImage:renderingModeImage forState:UIControlStateNormal];
[btnClear setImage:renderingModeImage forState:UIControlStateSelected];
}
[btnClear setTintColor:color];