UIAlertController 修改文字显示实现方法
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 修改文字显示实现方法的更多相关文章
- c# ToolStrip控件图片和文字显示--原创
如上图达到这样的效果 首先我们给属性Image和Text分别赋予需要显示的图片和文字 然后设置DisplyStyle属性为ImageAndText,意为同时显示图片和文字 各种设置ImageAlign ...
- Android--TextView 文字显示和修改
一. 新建一个Activity 和 Layout 首先在layout文件夹中新建一个activity_main.xml,在新建工程的时候一般默认会新建此xml文件,修改其代码如下: <Relat ...
- html使用css让文字超出部分用省略号三个点显示的方法案例
html使用css让文字超出部分用省略号三个点显示的方法: 我正确使用的就是下面的代码,li里面是a标记.在IE和google中使用是正常的,火狐不知道,我也不在意,等你来测 li{ display: ...
- Cell 动态行高文字显示不全问题探索
目录 问题概述 一.新建工程 二.尝试复现问题 尝试解决 修改contentLblBtmCon优先级为High(750) 修改contentLblBtmCon优先级为Low(250) 小结 其他解决思 ...
- Android之hint提示字体大小修改,显示完全
Android之hint提示字体大小修改,显示完全 1.工作中遇到一个问题,就是自定义EditText的hint提示在超大字体下会显示不全, 2.然后在网上搜索了一下,在这里记录一下,分享给大家,在此 ...
- Linux环境变量的修改(永久,暂时)以及修改ls显示的时间格式
本文转自:http://blog.sina.com.cn/s/blog_8e21864f01014u9h.html Linux修改环境变量,很简单但很重要 一.Linux的变量种类 按变量的生存周期来 ...
- thinkphp分页时修改last显示标题
需要修改Page.class.php里lastSuffix为false,这样才能修改last显示标题. 然后就可以设置了 或者直接在方法中声明: $p->lastSuffix = false; ...
- MyEclipse默认编码为GBK,修改为UTF8的方法
MyEclipse 默认编码居然是GBK,js文件默认编码是ISO-....怎么可以这样呢? 都修改成UTF8的方法: 1.windows->Preferences...打开"首选项& ...
- css控制竖直文字显示
假如有一天,你把水平文字看腻味了...... 我建议你不妨试试垂直文字显示,就像这样: 我 是 竖 直 显 示 的 : 哈哈! 言归正传,怎么把一段话,垂直显示呢? 方法1: //把下面代码另存为ht ...
随机推荐
- XNOR-Net:二值化卷积神经网络
https://www.jianshu.com/p/f9b015cc4514 https://github.com/hpi-xnor/BMXNet BMXNet:基于MXNet的开源二值神经网络实现 ...
- docker中mysql pxc集群
PXC集群 https://hub.docker.com/r/percona/percona-xtradb-cluster 安装PXC镜像 下载镜像或者导入本地镜像 docker pull perco ...
- Shell流程控制语句for
for语法格式: for 变量 in 参数列表 do 命令 done 或者 for 变量 in 参数列表 ; do 命令 done for语句流程控制图: 实例: [root@youxi1 ~]# v ...
- Python - Django - 使用 Bootstrap 样式修改注册页
reg2 函数: from django.shortcuts import render, HttpResponse from app01 import models def reg2(request ...
- c++11 为什么使用ref,和引用的区别
std::ref只是尝试模拟引用传递,并不能真正变成引用,在非模板情况下,std::ref根本没法实现引用传递,只有模板自动推导类型时,ref能用包装类型reference_wrapper来代替原本会 ...
- [LeetCode] 495. Teemo Attacking 提莫攻击
In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...
- Harbor密码重置 密码修改 admin密码重置
Harbor密码重置harbor现在是使用postgresql 数据库了.不再支持mysql,网上有N多重置Mysql密码的,可以略过了.我密码错了默认的Harbor12345 修改为: RedHat ...
- HSRP 实验
一.环境准备 1. 软件:GNS3 2. 路由:c7200 二.实验操作 实验要求: 1.理解HSRP的工作原理. 2.掌握HSRP配置方法. 3.理解HSRP的抢占与跟踪作用. 实验拓扑: 实验过程 ...
- TCP粘包和拆包的定义,产生的原因以及解决方案
TCP粘包:指发送方发送的若干数据包在接收方接收时粘成一团,从接收缓冲区看,后一包数据的头紧接着前一包数据的尾 产生的原因: 1.发送方的原因:TCP默认使用Nagle算法,而Nagle算法主要做两件 ...
- linux-sysbench
sysbench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况.关于这个项目的详细介绍请看:http://sysbench.sourceforge.ne ...