关于UIAlertAction如何修改sheet上的字体颜色
相信很多程序员都会遇到需求是这样的:

但是你发现无论怎么设置cancel和Destructive都无法让红色字体移动到下面取消按钮上:

其实之前一直用错,用了ios9之前的UIActionSheet这个view来当控件,但是发现,UIAlertController这个控制器用来做这个更好,只需一行代码就可以搞定。以下是我自己通过利用kvc去对字体颜色做改变的做法,希望有其他见解的可以随时交流。
- (void)viewDidLoad {
[super viewDidLoad];
self.button = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 100, 50)];
_button.backgroundColor = [UIColor blueColor];
[_button setTitle:@"性别" forState:UIControlStateNormal];
[_button addTarget:self action:@selector(selectSheet) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_button];
}
- (void)selectSheet
{
UIAlertAction *alertAct = [UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[_button setTitle:@"男" forState:UIControlStateNormal];
}];
UIAlertAction *alertAct1 = [UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[_button setTitle:@"女" forState:UIControlStateNormal];
}];
UIAlertAction *alertAct2 = [UIAlertAction actionWithTitle:@"保密" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[_button setTitle:@"保密" forState:UIControlStateNormal];
}];
UIAlertAction *alertAct3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
//******通过利用kvc对字体颜色进行修改 *******//
[alertAct3 setValue:[UIColor redColor] forKey:@"_titleTextColor"];
UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alertControl addAction:alertAct];
[alertControl addAction:alertAct1];
[alertControl addAction:alertAct2];
[alertControl addAction:alertAct3];
[self presentViewController:alertControl animated:YES completion:nil];
}
关于UIAlertAction如何修改sheet上的字体颜色的更多相关文章
- 修改TabBarViewController上标题字体颜色
UINavigationController *newNavVc = [[UINavigationController alloc]init]; newNavVc.title = title; new ...
- runtime查找 UIAlertAction 的key 及 UIActionSheet 设置字体颜色
修改不了颜色了 结果发现kvo 的key 不对 哎 直接上代码 设置正确的属性找到对应的key 还以为iOS 11改变了方法 unsigned int count; Ivar *ivars = c ...
- WPS修改批注部分的字体颜色?
今天遇到一个问题,就是复制文档的时候有几块红色字体想改成黑色,怎么也改不成功,通过修改字体颜色无效,通过百度找到了解决方法记录一下. 解决方法 审阅--显示标记--点击插入和删除(去掉前面的对钩即可) ...
- NPOI 修改指定单元格字体颜色
//创建一个字体颜色 IFont font = hssfworkbook.CreateFont(); //红色 font.Color = HSSFColor.Red.Index; //样式 ICell ...
- Android Them+SharedPreferences 修改程序所有view字体颜色、大小和页面背景
有这么一个需求,可以对页面的样式进行选择,然后根据选择改变程序所有字体颜色和页面背景.同时下一次启动程序,当前设置依然有效. 根据需求,我们需要一种快速,方便,有效的方式来实现需求,然后可以通过And ...
- 修改Vim内注释字体颜色
vim /etc/vimrc 然后按大写 G 到最后一行,插入 hi comment ctermfg=6 wq保存退出 PS:默认的注释颜色是4 然后有0,1,2,3,4,5 ...
- ECharts修改坐标轴,坐标轴字体,坐标轴网格样式以及控制坐标轴是否显示
转自:http://blog.csdn.net/kirinlau/article/details/72876689 首先要将一个图表显示在前端页面上: var myChart = echarts.in ...
- 修改UITextfield的Placeholder字体的颜色
- (void)viewDidLoad { [super viewDidLoad]; self.title=@"修改UITextField的placeholder字体颜色"; UI ...
- textFiled的placeHolder字体颜色
self.title=@"修改UITextField的placeholder字体颜色"; UITextField *textTF=[[UITextField alloc]initW ...
随机推荐
- POJ 2226二分图最大匹配
匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名.匈牙利算法是基于Hall定理中充分性证明的思想,它是二部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图 ...
- mybatis批量删除提示类型错误
一. 这里主要考虑两种参数类型:数组或者集合. 而这点区别主要体现在EmpMapper.xml文件中标签的collection属性: 当collection="array"时,表名 ...
- 【Kubernetes】K8S 网络隔离 方案
参考资料: K8S-网络隔离参考 OpenContrail is an open source network virtualization platform for the cloud. – Kub ...
- js中bind、call、apply函数的用法
最近一直在用 js 写游戏服务器,我也接触 js 时间不长,大学的时候用 js 做过一个 H3C 的 web的项目,然后在腾讯实习的时候用 js 写过一些奇怪的程序,自己也用 js 写过几个的网站.但 ...
- Python~字典
if not isinstance(x, (int, float)): raise TypeError('bad operand type') range() raw_input(‘birth’) ...
- 本周psp个人作业
计划--用一天的时间来做这个项目 需求分析--作为一个观众,我想要知道每局的比分,以便我更了解比赛情况. 生成设计文档--用类图来进行说明. 设计复审---无 代码规范--3H 具体设计--建立数据库 ...
- 【python】with的实现方法
来源:http://www.ibm.com/developerworks/cn/opensource/os-cn-pythonwith/#icomments 重点: with方法适用于需要分配和清理资 ...
- js 数组删去重复的加上没有的元素
为了一个数组的删除操作竟然费了一个多小时,下面分享一下我的代码: 代码功能:判断数组里是否有我要看的元素,如果没有就添加到数组里,如果有就去掉. var selectArr=[]; function ...
- idea Error:java: Compilation failed: internal java compiler error
idea 遇到Error:java: Compilation failed: internal java compiler error 是提示说你当前使用的编译器jdk版本不对. 按住Ctrl+Alt ...
- Linux创建定时任务
例如: 要求每天23:59分备份lampp日志: 备份的文件名以当时的时间命名 格式为:201612241852_acces.log 备份到:/tmp/logs/目录下 1.新建shell脚本:vim ...