zoukankan      html  css  js  c++  java
  • iOS改变UIAlertView、UIActionSheet、UIAlertController系统字体颜色

     废话不多说,直接上代码,效果是最好的说服力

    1、改变UIAlertView字体颜色

    [UIView appearance].tintColor = [UIColor greenColor];

     由于在iOS 8推出UIAlertController取代UIAlertView,关于UIAlertController修改颜色请见下面 3

    个人还是比较喜欢使用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];

    }

  • 相关阅读:
    关于 未能加载文件或程序集“ImageMagickNet”或它的某一个依赖项。试图加载格式不正确的程序 的解决办法
    Nhibernate中 ManyToOne 中lazy="proxy" 延迟不起作用的原因
    关于mysqlconnectornet6.3.4 MySqlDataAdapter 在空数据的情况下填充DataSet后tables[0] 找不到的问题
    JavaScript:constructor属性
    关于AspNetPager 采用URL分页时 执行两次绑定的解决办法
    WPF学习笔记(一)
    unity3d 屏幕坐标、鼠标位置、视口坐标和绘制GUI时使用的坐标
    FileUpLoad用法(二)上传文件到服务器的数据库
    ASP.Net 使用GridView模板删除一行的用法
    ASP.Net FileUpLoad 控件的用法(一)——上传到服务器文件夹下
  • 原文地址:https://www.cnblogs.com/yang-shuai/p/6673145.html
Copyright © 2011-2022 走看看