iOS runtime加KVC更改系统控件颜色

参考:https://www.jianshu.com/p/e22e5498164a

//
//  ViewController.m
//  UIAlertViewContents
//
//  Created by 123 on 2018/3/8.
//  Copyright © 2018年 123. All rights reserved.
//

#import "ViewController.h"
#import <objc/runtime.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    unsigned int count = 0;
    Ivar *ivars = class_copyIvarList([UIAlertAction class], &count);
    for (int i = 0; i<count; i++) {
        Ivar ivar = ivars[i];
        NSLog(@"%s------%s", ivar_getName(ivar), ivar_getTypeEncoding(ivar));
    }
}

- (IBAction)showAlert:(UIButton *)sender {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"测试" message:@"改变按钮颜色" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *testAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [testAction setValue:[UIColor redColor] forKey:@"titleTextColor"];
    [alertController addAction:testAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

@end

Simulator Screen Shot - iPhone 6s - 2018-03-08 at 18.15.33.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容