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];
}
最新文章
- struts2.5的配置及其注意事项
- Redis复制与可扩展集群搭建
- 怎样学习Scala泛函编程
- NSNotification Name 最佳写法
- 必须正确理解的---ng指令中的compile与link函数解析
- 未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序。
- zend
- centos6.4 挂载ntfs分区
- Codeforces Gym 100114 A. Hanoi tower 找规律
- decodeURIComponent
- IOS详解TableView——选项抽屉(天猫商品列表)
- handsontable插件HOOK事件
- git创建分支
- spring boot无法启动,或者正常启动之后无法访问报404的解决办法
- struts2(三)之表单参数自动封装与参数类型自动转换
- Pivotal开源基于PostgreSQL的数据库Greenplum
- hyperopt自动调参
- 几个js框架
- @Pointcut的用法
- mysql与redis在各种情况下性能对比
热门文章
- HDU 1033 Edge[地图型模拟/给你一串字符串,A代表以此点为参照顺时针90°,V代表逆时针90°]
- React 入门之路
- [转] 使用SVN进行源码管理
- IOS7开发~API变化
- cocos2dx 2.x新建项目
- LeetCode Recover Binary Search Tree——二查搜索树中两个节点错误
- HBase笔记
- js:string转int
- zabbix agent shell一键安装脚本
- JSP简单练习-用Servlet获取表单数据