#import <UIKit/UIKit.h>
@interface WAlertAction : UIAlertAction
@property(strong,nonatomic) UIColor *titleColor;
@end
@interface WAlertController : UIAlertController
@property(strong,nonatomic) UIColor *tintColor;
@property(strong,nonatomic) UIColor *titleColor;
@property(strong,nonatomic) UIColor *messageColor;
@end
#import "WAlertController.h"
#import <objc/runtime.h>
@implementation WAlertAction
-(void)setTitleColor:(UIColor *)titleColor
{
_titleColor = titleColor;
unsigned int count = 0;
Ivar *ivars = class_copyIvarList([UIAlertAction class], &count);
for (int i = 0; i < count; i ++) {
Ivar ivar = ivars[i];
NSString *ivarName = [NSString stringWithCString:ivar_getName(ivar) encoding:NSUTF8StringEncoding];
NSLog(@"%@",ivarName);
if ([ivarName isEqualToString:@"_titleTextColor"]) {
//NSMutableAttributedString *messageColor = [[NSMutableAttributedString alloc]initWithString:self.t attributes:@{NSForegroundColorAttributeName : [UIColor redColor]}];
[self setValue:titleColor forKey:@"titleTextColor"];
}
}
}
@end
@implementation WAlertController
- (void)viewDidLoad {
[super viewDidLoad];
unsigned int count = 0;
Ivar *ivars = class_copyIvarList([UIAlertController class], &count);
for (int i = 0; i < count; i ++) {
Ivar ivar = ivars[i];
NSString *ivarName = [NSString stringWithCString:ivar_getName(ivar) encoding:NSUTF8StringEncoding];
NSLog(@"%@",ivarName);
if ([ivarName isEqualToString:@"_attributedMessage"]) {
// NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:self.title attributes:@{NSForegroundColorAttributeName:self.titleColor,NSFontAttributeName:[UIFont boldSystemFontOfSize:14.0]}];
NSMutableAttributedString *messageColor = [[NSMutableAttributedString alloc]initWithString:self.message attributes:@{NSForegroundColorAttributeName : [UIColor redColor]}];
[self setValue:messageColor forKey:@"attributedMessage"];
}else if ([ivarName isEqualToString:@"_attributedTitle"])
{
NSMutableAttributedString *messageColor = [[NSMutableAttributedString alloc]initWithString:self.title attributes:@{NSForegroundColorAttributeName : [UIColor purpleColor]}];
[self setValue:messageColor forKey:@"attributedTitle"];
}
}
}
-(void)setTintColor:(UIColor *)tintColor
{
unsigned int count = 0;
Ivar *ivars = class_copyIvarList([UIAlertController class], &count);
for (int i = 0; i < count; i ++) {
Ivar ivar = ivars[i];
NSString *ivarName = [NSString stringWithCString:ivar_getName(ivar) encoding:NSUTF8StringEncoding];
NSLog(@"%@",ivarName);
}
}
@end