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

    }

  • 相关阅读:
    ironic port bind
    pdb /usr/bin/neutron-server
    networking_generic_switch
    [CodeForces586D]Phillip and Trains
    [CodeForces598D]Igor In the Museum
    [poj3468]A Simple Problem with Integers
    [bzoj1503][NOI2004]郁闷的出纳员
    [bzoj1208][HNOI2004]宠物收养所
    [luogu3384][模板]树链剖分
    [CodeForces869A]The Artful Expedient
  • 原文地址:https://www.cnblogs.com/leqoqo/p/7777301.html
Copyright © 2011-2022 走看看