UIAlertController修改文字显示

不废话先上完整代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"提示内容" preferredStyle:UIAlertControllerStyleAlert];
    //修改标题
    NSMutableAttributedString *attrTitle = [[NSMutableAttributedString alloc] initWithString:@"提示"];
    [attrTitle addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, [[attrTitle string] length])];
    [attrTitle addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, [[attrTitle string] length])];
    [alertController setValue: attrTitle forKey:@"attributedTitle"];
    //修改message
    NSMutableAttributedString * attrMessage = [[NSMutableAttributedString alloc] initWithString:@"提示内容"];
    [attrMessage addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, [[attrMessage string] length])];
    [attrMessage addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, [[attrMessage string] length])];
    [alertController setValue: attrMessage forKey:@"attributedMessage"];
    //修改按钮的颜色,同上可以使用同样的方法修改内容,样式
    UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [defaultAction setValue:[UIColor orangeColor] forKey:@"_titleTextColor"];
    [cancelAction setValue:[UIColor blueColor] forKey:@"_titleTextColor"];
 
    [alertController addAction:defaultAction];
    [alertController addAction:cancelAction];
    [self presentViewController:alertController animated:YES completion:nil];

修改标题属性

key: attributedTitle

1
2
3
4
5
//修改标题的内容,字号,颜色。使用的key值是“attributedTitle"
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"标题"];
    [attr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:50] range:NSMakeRange(0, [[attr string] length])];
    [attr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, [[hogan string] length])];
    [alertController setValue:hogan forKey:@"attributedTitle"];

修改内容属性

key: attributedMessage

1
2
3
4
5
//修改message
    NSMutableAttributedString * attrMessage = [[NSMutableAttributedString alloc] initWithString:@"提示内容"];
    [attrMessage addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, [[attrMessage string] length])];
    [attrMessage addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, [[attrMessage string] length])];
    [alertController setValue: attrMessage forKey:@"attributedMessage"];

标题AlertAction按钮字体颜色

key: _titleTextColor或者titleTextColor

1
2
3
4
5
6
7
8
9
//修改按钮的颜色,同上可以使用同样的方法修改内容,样式
   UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
   UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
 
   [defaultAction setValue:[UIColor blackColor] forKey:@"_titleTextColor"];
   [cancelAction setValue:[UIColor blackColor] forKey:@"_titleTextColor"];
 
   [alertController addAction:defaultAction];
   [alertController addAction:cancelAction];

效果图

UIAlertController 修改文字显示实现方法的更多相关文章

  1. c# ToolStrip控件图片和文字显示--原创

    如上图达到这样的效果 首先我们给属性Image和Text分别赋予需要显示的图片和文字 然后设置DisplyStyle属性为ImageAndText,意为同时显示图片和文字 各种设置ImageAlign ...

  2. Android--TextView 文字显示和修改

    一. 新建一个Activity 和 Layout 首先在layout文件夹中新建一个activity_main.xml,在新建工程的时候一般默认会新建此xml文件,修改其代码如下: <Relat ...

  3. html使用css让文字超出部分用省略号三个点显示的方法案例

    html使用css让文字超出部分用省略号三个点显示的方法: 我正确使用的就是下面的代码,li里面是a标记.在IE和google中使用是正常的,火狐不知道,我也不在意,等你来测 li{ display: ...

  4. Cell 动态行高文字显示不全问题探索

    目录 问题概述 一.新建工程 二.尝试复现问题 尝试解决 修改contentLblBtmCon优先级为High(750) 修改contentLblBtmCon优先级为Low(250) 小结 其他解决思 ...

  5. Android之hint提示字体大小修改,显示完全

    Android之hint提示字体大小修改,显示完全 1.工作中遇到一个问题,就是自定义EditText的hint提示在超大字体下会显示不全, 2.然后在网上搜索了一下,在这里记录一下,分享给大家,在此 ...

  6. Linux环境变量的修改(永久,暂时)以及修改ls显示的时间格式

    本文转自:http://blog.sina.com.cn/s/blog_8e21864f01014u9h.html Linux修改环境变量,很简单但很重要 一.Linux的变量种类 按变量的生存周期来 ...

  7. thinkphp分页时修改last显示标题

    需要修改Page.class.php里lastSuffix为false,这样才能修改last显示标题. 然后就可以设置了 或者直接在方法中声明: $p->lastSuffix = false; ...

  8. MyEclipse默认编码为GBK,修改为UTF8的方法

    MyEclipse 默认编码居然是GBK,js文件默认编码是ISO-....怎么可以这样呢? 都修改成UTF8的方法: 1.windows->Preferences...打开"首选项& ...

  9. css控制竖直文字显示

    假如有一天,你把水平文字看腻味了...... 我建议你不妨试试垂直文字显示,就像这样: 我 是 竖 直 显 示 的 : 哈哈! 言归正传,怎么把一段话,垂直显示呢? 方法1: //把下面代码另存为ht ...

随机推荐

  1. Nim游戏博弈(收集完全版)

    Nim游戏证明参见: 刘汝佳训练指南P135-写的很酷! 知乎上SimonS关于Nim博弈的回答! Nim游戏的概述: 还记得这个游戏吗? 给出n列珍珠,两人轮流取珍珠,每次在某一列中取至少1颗珍珠, ...

  2. Linux下打开超大文件的方法

    Linux下打开超大文件方法 在Linux下用VIM打开大小几个G.甚至几十个G的文件时,是非常慢的. 这时,我们可以利用下面的方法分割文件,然后再打开. 1 查看文件的前多少行 head -1000 ...

  3. 【Linux】宝塔服务器磁盘爆满处理方法

    直接上图 1 清理网站日志/php站点session/系统邮件/临时文件 cd /www/server/panel && python tools.pyc clear 2 清空面板回收 ...

  4. apicloud打包成apk

    前言:本文是打包vue项目,其他项目也是这样打包 页面的开发过程跟我们平时开发一样,利用vue把页面全部完成,最后进行npm run build将项目打包. 接下来就是apicloud打包的过程,首先 ...

  5. [Bayes] Concept Search and LSI

    基于术语关系的贝叶斯网络信息检索模型扩展研究 LSI 阅读笔记 背景知识 提出一种改进的共现频率法,利用该方法挖掘了索引术语之间的相关关系,将这种相关关系引入信念网络模型,提出了一个具有两层术语节点的 ...

  6. KAFKA:如何做到1秒发布百万级条消息

    http://rdcqii.hundsun.com/portal/article/709.html KAFKA是分布式发布-订阅消息系统,是一个分布式的,可划分的,冗余备份的持久性的日志服务.它主要用 ...

  7. eclipse :代码自动补全不生效解决办法

    参考文章:https://blog.csdn.net/qq_35033270/article/details/79285821 请见下图! 恢复缺省值即可!

  8. [LeetCode] 89. Gray Code 格雷码

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  9. 【剑指offer】面试题 19. 正则表达式匹配

    面试题 19. 正则表达式匹配

  10. iframe跨端口报错 Blocked a frame with origin from accessing a cross-origin frame

    前言    在不同的端口号,甚至是不同的ip进行iframe嵌套的时候,在父页面调用子页面的方法的时候,报错 SecurityError: Blocked a frame with origin fr ...