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 911F Tree Destruction(贪心 && 树的直径)
题目链接 Tree Destructi 题意 给定一棵树,每次可以选定树上的两个叶子,并删去其中的一个.答案每次加上两个选定的叶子之间的距离. 求最后答案的最大值. 首先求出树的某一条直径,令其端 ...
- 代码Rework中的反思
以前编码只是关注能写出来,并让程序运行就完事,这是非常错误的想法. 让我们重新思考软件设计中的一些问题吧! 软件设计就像设计房屋,设计器具,是一个道理.软件的复杂度和bug完全是自己造成的,要设计好的 ...
- 学习GRPC(一) 简单实现
Grpc 实现流程图 资料 https://grpc.io/docs/quickstart/go/ https://studygolang.com/articles/16627 使用方法 make r ...
- 获取元素位置信息和所占空间大小(via:js&jquery)
工作中有一个很常见的需求,hover或者click某元素后,在该元素旁边出现弹框,主要就是获取该元素的位置坐标以及元素所占区块的大小.最近工作中就遇到了,发现js和jquery的实现方法有很大的区别, ...
- Youtube深度学习推荐系统论文
https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/45530.pdf https://zh ...
- C# Graphics
Graphics.FillPie 方法 填充由一对坐标.一个宽度.一个高度以及两条射线指定的椭圆所定义的扇形区的内部. Graphics.FillPie (Brush, Int32, Int32, I ...
- xml 文件不给提示(以mybatis 的 mapper映射文件为例)
在xxx.xml 映射文件的头部可以看到 如下: (mybatis generate 自动生成) <!DOCTYPE mapper PUBLIC "-//mybatis.org//DT ...
- NYOJ92 图像实用区域 【BFS】
碰到了一个曾经从未见过的奇怪问题:先上截图: 执行号 用户 题目 结果 时间 内存 语言 提交时间 895360 userid=%E9%95%BF%E6%9C%A8" style=" ...
- python 查询,子查询以及1对多查询
1.添加数据: # 方法1:对象.save() book = Book(**kwargs) book.save() # 方法2:类.create(**kwargs) Book.create(**kwa ...
- vue2.X v-model 指令
1.v-model指令 <!DOCTYPE html> <html> <head> <title></title> <script s ...