博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
个性化 UIAlertController
阅读量:7069 次
发布时间:2019-06-28

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

系统的 UIAlertController 封装的很漂亮,用block代替之前 UIAlertView 的代理,用起来更方便的,但是其曝露出来的接口也不多如果要个性化一些东西,比如字体大小、颜色就不是很方便了,下面总结一下 UIAlertController 更改字体的方法,以作备忘:

1、UIAlertController 的标题(Title)、和描述(Message) 可以更改字体的大小和颜色

NSAttributedString *attTitle = [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16], NSForegroundColorAttributeName : [UIColor colorWithHexstring:@"333333"]}];    [alert setValue:attTitle forKey:@"attributedTitle"];
NSAttributedString *attMessage = [[NSAttributedString alloc] initWithString:message attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16], NSForegroundColorAttributeName : [UIColor colorWithHexstring:@"333333"]}];        [alert setValue:attMessage forKey:@"attributedMessage"];

这样可以设置 alert 的title,和 message 。注意会覆盖 alert 初始化时填写的值。

2、UIAlertController 的按钮(action) 可以更改字体颜色,字体大小没找到怎么改

UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {            }];[sureAction setValue:[UIColor colorWithHexstring:@"18a74f"] forKey:@"titleTextColor"];

 

转载于:https://www.cnblogs.com/shenhongbang/p/5430201.html

你可能感兴趣的文章
VMware Horzion Workspace POC文档--安装2(集成VIEW)
查看>>
浅谈HDFS的读流程
查看>>
【探索】VS下虚继承实现的方法-1
查看>>
Java基础加密之MD5加密算法
查看>>
盛夏光年
查看>>
Android 沉浸式状态栏(像IOS那样的状态栏与应用统一颜色样式)
查看>>
RHCS集群服务 7.10
查看>>
windows 使用vnc图形化界面远程连接阿里云ubuntu 16.04云服务器
查看>>
linux和CentOS是什么关系;CentOS和RHEL是什么关系
查看>>
samba
查看>>
利用Python网络爬虫抓取微信好友的签名及其可视化展示
查看>>
Linux-Nginx代理
查看>>
计算机的系统组成简介---运维笔记
查看>>
Liunx nginx 的使用方法及模块
查看>>
DBA——表级数据恢复之路(一) 请下载附件查看
查看>>
自定义弹出框
查看>>
如何扩展ESXi虚拟机磁盘容量
查看>>
sqlserver 登录方式修改,由默认的windows账户改为用sa等sql server账户登录
查看>>
Apache+tomcat 快速部署Java环境
查看>>
获取Android控件尺寸
查看>>