iOS 自定义UIAlertController的title、m

作者: CodeGeass | 来源:发表于2017-11-28 10:17 被阅读53次

    有时设计要求改弹窗的颜色,so,改吧

    #import <UIKit/UIKit.h>
    
    @interface UIAlertAction (ZDExtension)
    
    - (void)zd_setTitleColor:(UIColor *)color;
    
    @end
    
    @interface UIAlertController (ZDExtension)
    
    - (void)zd_setTitleColor:(UIColor *)color;
    
    - (void)zd_setAttributedTitle:(NSAttributedString *)title;
    
    - (void)zd_setMessageColor:(UIColor *)color;
    
    - (void)zd_setAttributedMessage:(NSAttributedString *)message;
    
    - (void)zd_setActionTitleColor:(UIColor *)color;
    
    @end
    
    @implementation UIAlertAction (ZDExtension)
    
    - (void)zd_setTitleColor:(UIColor *)color {
        [self setValue:color forKey:@"titleTextColor"];
    }
    
    @end
    
    @implementation UIAlertController (ZDExtension)
    
    - (void)zd_setTitleColor:(UIColor *)color {
        NSAttributedString *string = [[NSAttributedString alloc] initWithString:self.title attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17],NSForegroundColorAttributeName:color}];
        [self zd_setAttributedTitle:string];
    }
    
    - (void)zd_setAttributedTitle:(NSAttributedString *)title {
        [self setValue:title forKey:@"attributedTitle"];
    }
    
    - (void)zd_setMessageColor:(UIColor *)color {
        NSAttributedString *string = [[NSAttributedString alloc] initWithString:self.message attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13],NSForegroundColorAttributeName:color}];
        [self zd_setAttributedMessage:string];
    }
    
    - (void)zd_setAttributedMessage:(NSAttributedString *)message {
        [self setValue:message forKey:@"attributedMessage"];
    }
    
    - (void)zd_setActionTitleColor:(UIColor *)color {
        for (UIAlertAction *action in self.actions) {
            [action zd_setTitleColor:color];
        }
    }
    
    @end
    

    相关文章

      网友评论

        本文标题:iOS 自定义UIAlertController的title、m

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