美文网首页iOS
iOS runtime加KVC更改系统控件颜色

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

作者: 飞鱼ll | 来源:发表于2018-03-08 18:14 被阅读0次

    参考: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

    相关文章

      网友评论

        本文标题:iOS runtime加KVC更改系统控件颜色

        本文链接:https://www.haomeiwen.com/subject/twwyfftx.html