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];

    }

  • 相关阅读:
    markdown
    线段树模板
    Trie模板 UVALive 3942 Remember the Word
    使用swift写sprite Kit的模仿微信打飞机游戏
    Graffiti support page
    使用代码控制ScrollView的contentSize
    资料整理
    pd.to_sql()用法
    如何将表格的数据导入到mysql
    安装启动MySQL8.0,报错:1053
  • 原文地址:https://www.cnblogs.com/leqoqo/p/7777301.html
Copyright © 2011-2022 走看看