UITextField 自定义clearButton背景色
一个鸡贼的解决方案,适用于自定义clearButton的样式,直接修改背景图即可
1. 实现基于UITextField的category并添加如下方法及声明
- (void)setLightStyle:(BOOL)lightStyle {
UIButton *clearButton = [self valueForKey:@"_clearButton"];
[clearButton setImage:@"clearButton".image forState:0];
[clearButton setImage:@"clearButton".image forState:1];
}
2. Appdelegate中程序启动后执行全局样式替换
[[UITextField appearance] setLightStyle:YES];
3. surprise!!