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];

    }

  • 相关阅读:
    linux下activemq安装与配置
    Linux设置开放一个端口
    使用codis-admin搭建codis集群
    elasticsearch7.0安装及配置优化
    ELK详细安装部署
    filebeat安装部署
    ElasticSearch-5.3.1集群环境搭建,安装ElasticSearch-head插件,安装错误解决
    手把手教你搭建一个 Elasticsearch 集群
    ES 集群管理(集群规划、集群搭建、集群管理)
    Elasticsearch如何关掉服务
  • 原文地址:https://www.cnblogs.com/yang-shuai/p/6673145.html
Copyright © 2011-2022 走看看