zoukankan      html  css  js  c++  java
  • iOS之改变UIAlertViewController字体的颜色

    NSString *message = @"请确认信息是否正确?";
    NSString *title = @"提示";
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
    //改变title的大小和颜色
    NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:title];
    [titleAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(0, title.length)];
    [titleAtt addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, title.length)];
    [alertController setValue:titleAtt forKey:@"attributedTitle"];
    //改变message的大小和颜色
    NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:message];
    [messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0, message.length)];
    [messageAtt addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0, message.length)];
    [alertController setValue:messageAtt forKey:@"attributedMessage"];
     [self presentViewController:alertController animated:YES completion:nil];

    上面的是修改UIAlertViewController的title和message字体的大小和颜色,采用的是修改attributedString其中的NSForegroundColorAttributeName颜色属性和NSFontAttributeName字体大小属性。UIAlertViewController中的标题的key:@"attributedTitle",标题中提示信息的key:@"attributedMessage"。

    UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:nil];
    [alertAction setValue:[UIColor purpleColor] forKey:@"_titleTextColor"];
    //    alertController.view.tintColor = [UIColor greenColor];
    [alertController addAction:alertAction];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    /*取消按钮的颜色*/
    [cancel setValue:[UIColor redColor] forKey:@"_titleTextColor"];
    [alertController addAction:cancel];

    修改UIAlertViewController中修改所有按钮的颜色使用下面这个方法:

    alertController.view.tintColor = [UIColor greenColor];

    修改单个UIAlertAction按钮的字体颜色使用下面这个方法:

    [cancel setValue:[UIColor redColor] forKey:@"_titleTextColor"];
  • 相关阅读:
    TCP 协议三次握手过程解析带实例
    一些关于反汇编与逆向方面的博文分享
    关于mwArray和一般数组的区别
    vc6.0 使用Ado 连接MS-SqlServer2000 连接字符串
    VC6使用技巧
    Oracle性能诊断艺术-读书笔记(执行计划中显示 Starts, E-Rows, REM A-Rows and A-Time)等)
    Oracle性能诊断艺术-读书笔记
    linux 检查补丁包是否安装 名称 版本 release号
    我叫他小北
    Oracle linux安装Oracle 11G
  • 原文地址:https://www.cnblogs.com/rglmuselily/p/6868275.html
Copyright © 2011-2022 走看看