博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
改变UIAlertController的标题、内容的字体和颜色
阅读量:7110 次
发布时间:2019-06-28

本文共 2035 字,大约阅读时间需要 6 分钟。

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

}

转载于:https://www.cnblogs.com/leqoqo/p/7777301.html

你可能感兴趣的文章
MyCAT实现MySQL的读写分离
查看>>
Codeforces554A:Kyoya and Photobooks
查看>>
PHP curl_setopt函数用法介绍补充篇
查看>>
汇编题目:在屏幕中间显示a-z的所有字母,按ESC键改变字符颜色
查看>>
AIM Tech Round (Div. 2) D. Array GCD dp
查看>>
Codeforces Round #249 (Div. 2) A B
查看>>
c++11 新特性之 autokeyword
查看>>
HDU 5627 Clarke and MST &意义下最大生成树 贪心
查看>>
jQuery html表格排序插件:tablesorter
查看>>
myeclipse10不用打开myeclipse configuration center安装插件的方法
查看>>
hbase自带mapreduce计数表行数功能
查看>>
Spring中自己主动装配
查看>>
数组去重复
查看>>
Swift - guard关键字(守护)
查看>>
sqlite数据库读写在linux下的权限问题
查看>>
sharepreference实现记住password功能
查看>>
http与https的区别
查看>>
【JavaScript】ReactJS&NodeJS了解资料
查看>>
springMVC demo搭建
查看>>
Android 百分比布局库(percent-support-lib) 解析与扩展
查看>>