美文网首页
个性化 UIAlertController

个性化 UIAlertController

作者: 九天环佩 | 来源:发表于2016-07-15 21:22 被阅读62次

    系统的 UIAlertController 封装的很漂亮,用block代替之前 UIAlertView 的代理,用起来更方便的,但是其曝露出来的接口也不多如果要个性化一些东西,比如字体大小、颜色就不是很方便了,下面总结一下 UIAlertController 更改字体的方法,以作备忘:

    1、UIAlertController 的标题(Title)、和描述(Message) 可以更改字体的大小和颜色

    NSAttributedString *attTitle = [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16], NSForegroundColorAttributeName : [UIColor colorWithHexstring:@"333333"]}];
        [alert setValue:attTitle forKey:@"attributedTitle"];
    
    NSAttributedString *attMessage = [[NSAttributedString alloc] initWithString:message attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16], NSForegroundColorAttributeName : [UIColor colorWithHexstring:@"333333"]}];
            [alert setValue:attMessage forKey:@"attributedMessage"];
    

    这样可以设置 alert 的title,和 message 。注意会覆盖 alert 初始化时填写的值。

    2、UIAlertController 的按钮(action) 可以更改字体颜色,字体大小没找到怎么改

    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
    [sureAction setValue:[UIColor colorWithHexstring:@"18a74f"] forKey:@"titleTextColor"];
    





    相关文章

      网友评论

          本文标题:个性化 UIAlertController

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