zoukankan      html  css  js  c++  java
  • 在iOS7中修改状态栏字体的颜色

    http://www.2cto.com/kf/201408/324442.html

    默认状态栏的字体为黑色:UIStatusBarStyleDefault

    状态栏的字体为白色:UIStatusBarStyleLightContent

    一、在info.plist中,将View controller-based status bar appearance设为NO

    状态栏字体的颜色只由下面的属性设定,默认为白色:

    // default is UIStatusBarStyleDefault

    [UIApplication sharedApplication].statusBarStyle

    解决个别vc中状态栏字体颜色不同的办法

    1、在info.plist中,将View controller-based status bar appearance设为NO.

    2、在app delegate中:

    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

    3、在个别状态栏字体颜色不一样的vc中

    -(void)viewWillAppear:(BOOL)animated{

    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;

    }

    -(void)viewWillDisappear:(BOOL)animated

    {

    [super viewWillDisappear:animated];

    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

    }

    二、在info.plist中,将View controller-based status bar appearance设为YES,或者没有设置。

    View controller-based status bar appearance的默认值就是YES。

    如果View controller-based status bar appearance为YES。

    则[UIApplication sharedApplication].statusBarStyle 无效。

    用下面的方法:

    1、在vc中重写vc的preferredStatusBarStyle方法。

    -(UIStatusBarStyle)preferredStatusBarStyle

    {

    return UIStatusBarStyleDefault;

    }

    2、在viewDidload中调用:[self setNeedsStatusBarAppearanceUpdate];

    但是,当vc在nav中时,上面方法没用,vc中的preferredStatusBarStyle方法根本不用被调用。

    原因是,[self setNeedsStatusBarAppearanceUpdate]发出后,

    只会调用navigation controller中的preferredStatusBarStyle方法,

    vc中的preferredStatusBarStyley方法跟本不会被调用。

    解决办法有两个:

    方法一:

    设置navbar的barStyle 属性会影响status bar 的字体和背景色。如下。

    //status bar的字体为白色

    //导航栏的背景色是黑色。

    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

    //status bar的字体为黑色

    //导航栏的背景色是白色,状态栏的背景色也是白色。

    //self.navigationController.navigationBar.barStyle = UIBarStyleDefault;

    方法二:

    自定义一个nav bar的子类,在这个子类中重写preferredStatusBarStyle方法:

    MyNav* nav = [[MyNav alloc] initWithRootViewController:vc];

    self.window.rootViewController = nav;

    @implementation MyNav

    - (UIStatusBarStyle)preferredStatusBarStyle

    {

    UIViewController* topVC = self.topViewController;

    return [topVC preferredStatusBarStyle];

    }

  • 相关阅读:
    软件需求阅读笔记二
    寒假小程序开发记录2
    软件需求阅读笔记一
    寒假小程序开发记录1
    软件工程概论课个人总结
    06大道至简阅读笔记
    golang算法——leetcode-46
    实验 5 Spark SQL 编程初级实践
    scala链接数据库Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    Error:(15, 103) value toDF is not a member of org.apache.spark.rdd.RDD[Employee] .map(attributes => Employee(attributes(0).trim.toInt, attributes(1), attributes(2).trim.toInt)).toDF()
  • 原文地址:https://www.cnblogs.com/apem/p/4025796.html
Copyright © 2011-2022 走看看