系统提示按钮字体颜色默认是蓝色,因为是在项目优化时产生的需求故使用拓展的方式解决。
#import "UIAlertController+GSActionBtn.h"
@implementation UIAlertController (GSActionBtn)
+ (void)load {
// 只执行一次
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[NSObject exchangeInstanceMethodWithSelfClass:UIAlertController.class originalSelector:@selector(addAction:) swizzledSelector:@selector(GSActionBtn_AddAction:)];
});
}
- (void)GSActionBtn_AddAction:(UIAlertAction *)action {
if ([action.title isEqualToString:@"取消"] && self.preferredStyle == UIAlertControllerStyleAlert) {
UIColor *tempColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
[action setValue:tempColor forKey:@"_titleTextColor"];
}
[self GSActionBtn_AddAction:action];
}
@end
示意图