zoukankan      html  css  js  c++  java
  • 改变UIAlertController的标题、内容的字体和颜色

    Jietu20171103 112214

     

    #import "ViewController.h"

     

    @interfaceViewController ()

     

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad {

      [superviewDidLoad];

      // Do any additional setup after loading the view, typically from a nib.

     

    }

     

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

      UIAlertController *alertController = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"提示内容"preferredStyle:UIAlertControllerStyleAlert];

      

      UIAlertAction *defaultAction = [UIAlertActionactionWithTitle:@"Default"style:UIAlertActionStyleDefaulthandler:nil];

      UIAlertAction *destructiveAction = [UIAlertActionactionWithTitle:@"Destructive"style:UIAlertActionStyleDestructivehandler:nil];

      UIAlertAction *cancelAction = [UIAlertActionactionWithTitle:@"Cancel"style:UIAlertActionStyleCancelhandler:nil];

      

      [alertController addAction:defaultAction];

      [alertController addAction:destructiveAction];

      [alertController addAction:cancelAction];

      

      

      //修改title

      NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedStringalloc] initWithString:@"提示"];

      [alertControllerStr addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor] range:NSMakeRange(0, 2)];

      [alertControllerStr addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:17] range:NSMakeRange(0, 2)];

      [alertController setValue:alertControllerStr forKey:@"attributedTitle"];

      

      //修改message

      NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedStringalloc] initWithString:@"提示内容"];

      [alertControllerMessageStr addAttribute:NSForegroundColorAttributeNamevalue:[UIColorgreenColor] range:NSMakeRange(0, 4)];

      [alertControllerMessageStr addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:20] range:NSMakeRange(0, 4)];

      [alertController setValue:alertControllerMessageStr forKey:@"attributedMessage"];

      

      //修改按钮

      if (![cancelAction valueForKey:@"titleTextColor"]) {

        [cancelAction setValue:[UIColorredColor] forKey:@"titleTextColor"];

      }

      

      [selfpresentViewController:alertController animated:YEScompletion:nil];

    }

  • 相关阅读:
    New starting
    Ubuntu中PyCharm中字体设置
    pyshp操作shapefile
    GIS的数学基础
    向mysql中插入Date类型的数据
    mysql多字段排序
    干掉命令行窗口下MySql乱码
    JavaWeb中读取文件资源的路径问题
    Java中9种IO的读取方式
    JavaIO 将数据写入到文件中去
  • 原文地址:https://www.cnblogs.com/leqoqo/p/7777301.html
Copyright © 2011-2022 走看看