iOS改变UIAlertView、UIActionSheet、UIAlertController系统字体颜色
废话不多说,直接上代码,效果是最好的说服力
1、改变UIAlertView字体颜色
[UIView appearance].tintColor = [UIColor greenColor];
个人还是比较喜欢使用UIAlertView,简单粗暴达到想要的效果
2、改变UIActionSheet字体颜色
// 改变 actionSheet字体颜色
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
SEL selector = NSSelectorFromString(@"_alertController");
if ([actionSheet respondsToSelector:selector])//ios8
{
UIAlertController *alertController = [actionSheet valueForKey:@"_alertController"];
if ([alertController isKindOfClass:[UIAlertController class]]) {
alertController.view.tintColor = [UIColor greenColor];
}
//ios7
} else{
for( UIView * subView in actionSheet.subviews ) {
if( [subView isKindOfClass:[UIButton class]] ) {
UIButton * btn = (UIButton*)subView;
[btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
}
}
}
}
3、改变UIAlertController字体颜色
- (void)buttonClick:(UIButton *)sender {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"提示内容" preferredStyle:UIAlertControllerStyleAlert];
//修改标题的内容,字号,颜色。使用的key值是“attributedTitle”
NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"heihei"];
[hogan addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:50] range:NSMakeRange(0, [[hogan string] length])];
[hogan addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, [[hogan string] length])];
[alertController setValue:hogan forKey:@"attributedTitle"];
//修改按钮的颜色,同上可以使用同样的方法修改内容,样式
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Default" style:UIAlertActionStyleDefault handler:nil];
[defaultAction setValue:[UIColor blueColor] forKey:@"_titleTextColor"];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[cancelAction setValue:[UIColor greenColor] forKey:@"_titleTextColor"];
[alertController addAction:defaultAction];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}
iOS改变UIAlertView、UIActionSheet、UIAlertController系统字体颜色的更多相关文章
- iOS开发之iOS7设置状态栏字体颜色
应用中登陆界面颜色较浅,状态栏字体颜色为黑色,跳转到主界面之后,界面颜色较深,状态栏颜色随之变成白色.但是再重新返回登陆界面后,状态栏字体颜色并没有改成黑色,特别别扭. plist文件里将View c ...
- ios修改textField的placeholder的字体颜色和大小
textField.placeholder = @"username is in here!"; [textField setValue:[UIColor redColor] fo ...
- ios修改textField的placeholder的字体颜色、大小
textField.placeholder = @"username is in here!"; [textField setValue:[UIColor redColor] fo ...
- ios 更改UITableview中Section的字体颜色
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UILabel *c ...
- 改变label中的某字体颜色
NSString *allString=@"你家在哪里,需要我送你么"; NSString *subString=@"在哪里"; UILabel *string ...
- H5表单中placeholder属性的字体颜色问题
最近做项目的时候遇到的一些小样式问题,有关表单.并且在接下来几天的面试人中五个人都没有回答上来,改变placeholder属性的默认字体颜色,感觉有必要总结一下. 如何改变默认字体的颜色? @blue ...
- js点击按钮为元素随机字体颜色和背景色
文章地址 https://www.cnblogs.com/sandraryan/ 写两个button和一个div,点击按钮分别改变背景色和前景色(字体颜色).产生的是一个随机颜色. <!DOCT ...
- IOS 修改UIAlertController的按钮标题的字体颜色,字号,内容
IOS 修改UIAlertController的按钮标题的字体颜色,字号,内容 UIAlertController *alertVC = [UIAlertController alertControl ...
- 【iOS学习笔记】改变状态栏字体颜色
Step1. info.plist中设置UIViewControllerBasedStatusBarAppearance为NO Step2. AppDelegate.m中添加 - (BOOL)appl ...
随机推荐
- Codeforces Round #454 C. Shockers【模拟/hash】
C. Shockers time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Delphi通过管道执行外部命令行程序(cmd)并获取返回结果
该代码片段来自于: http://www.sharejs.com/codes/delphi/8999,发现好多代码,想用的时候找不到,记录一下备用 function RunDosCommand(Com ...
- Debugging a SQL Server query with WinDbg
Debugging a SQL Server query with WinDbg May 13, 2014 · Klaus Aschenbrenner · 5 Comments (Be sure to ...
- Mac测试模拟慢网速
先普及一下Kb,KB,Kbps,Mb,Mbps等一些列概念 1Byte = 8bit 1KB (Kilobyte 千字节)=1024Byte 1MB (Megabyte,兆字节,简称“兆”)=1024 ...
- Beginning Auto Layout Tutorial in iOS 7: Part 2
Auto Layout to the rescue! 接下来就看看如何使用Auto Layout来实现这个效果. 首先移除viewWillLayoutSubviews方法,选择Main.storybo ...
- Oracle 11gR2 RAC 单网卡 转 双网卡绑定 配置步骤
之前写过一篇双网卡绑定的文章,如下: Oracle RAC 与 网卡绑定 http://blog.csdn.net/tianlesoftware/article/details/6189639 Ora ...
- PHP计算两个时间的年数、月数以及天数
如何获取两个不同时间相差几年几月几日呢?比如当前时间距离2008年08月08日的北京奥运会有几年几月几日了?需要说明的是:1.定义一年为360天,一个月为30天:2.代码中86400=24*60*60 ...
- OSG(OpenSceneGraphic) 渲染引擎架构--整体认识 [转]
原文:http://blog.csdn.net/zangle260/article/details/41123067?utm_source=tuicool 本文参考<<osg最长一帧> ...
- 正确理解hadoop 2.x 的环形缓冲区: (一) MR环形缓冲区的结构
转载:http://blog.csdn.net/HADOOP_83425744/article/details/49560583 http://bigdatadecode.club/MapReduce ...
- vue.js+koa2项目实战(六)数据库建表
数据库建表 1.打开 MySQL 终端 2.查看所有数据库 show databases 3.创建数据库 create database pet 4.进入数据库 use pet 5.创建数据表 cre ...