iOS runtime加KVC更改系统控件颜色
2018-03-08 本文已影响0人
飞鱼ll
参考: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