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

}

在iOS7中修改状态栏字体的颜色的更多相关文章

  1. 在iOS7中修改状态栏字体的颜色-b

    状态栏的字体为黑色: UIStatusBarStyleDefault 状态栏的字体为白色: UIStatusBarStyleLightContent 一.在 info.plist  中,将 View ...

  2. 在iOS7中改动状态栏字体的颜色

    状态栏的字体为黑色:UIStatusBarStyleDefault 状态栏的字体为白色:UIStatusBarStyleLightContent 一.在info.plist中,将View contro ...

  3. iOS7中修改StatusBar的显示颜色

    iOS7中修改StatusBar的显示颜色 效果图如下: 在iOS7中想手动修改statusBar的颜色,第一步需要做的就是在plist文件中设置View controller-based statu ...

  4. iOS 修改状态栏字体的颜色

    在实际开发中,状态栏有时,需要我们自己设置: 比如: 默认状态栏 假如我们开发的view是黑色的,那么效果如图: 状态栏是白底黑字,下面的view是黑底? 这样子真的好吗?说好的和谐社会呢?说好的开发 ...

  5. 自定义orgmode中加粗字体的颜色

    自定义orgmode中加粗字体的颜色 Table of Contents 1. orgmode中加粗字体的默认处理 2. 设置设置加粗字体的颜色 1 orgmode中加粗字体的默认处理 在orgmod ...

  6. Win10 中修改cmd字体引发的问题

    Win10 中修改cmd字体引发的问题 学习了:https://www.cnblogs.com/Diryboy/archive/2015/12/05/Use-Consolas-MSYaHei-in-C ...

  7. MathType中怎么设置字体默认颜色

    MathType功能非常强大,在编辑公式时使用非常方便.利用MathType破解版不仅可以改变公式的字体和字号,也可以改变公式字体颜色.有时在编辑完成后需要对MathType公式格式全部进行修改,这时 ...

  8. 在Visio2010中修改默认字体的大小

    由于我常需要在Visio2010中画流程图和UML图,但是Visio2010中的字体默认8px,这对眼睛是个挑战.摸索了好久终于找到在visio2010中修改字体大小的方式. 1.点一下红色箭头所指的 ...

  9. 在iOS7中修改键盘Return键的类型

    今天将之前运行在iOS7之前的一段代码拿出来,在iOS7的机器上运行,发现键盘上的ReturnKeyType不能被修改了. 经过几番查找资料,了解到iOS7中UISearchBar的结构发生了变化,将 ...

随机推荐

  1. python3 入门 (二) 列表的使用

    列表用于组织其它数值,即写在方括号之间.用逗号分隔开的数值列表.列表内的项目不必全是相同的类型. 列表的定义 student = ['Tom', 'Jack', 'Avril'] 添加元素 将另一个列 ...

  2. EntityFramework中的线程安全,又是Dictionary

    继上次记一次w3wp占用CPU过高的解决过程(Dictionary和线程安全)后又再次与Dictionary博弈,这一次是在EntityFramework中的Dictionary. 从一个异常说起 这 ...

  3. 16.C#初见Lambda表达式及表达式树(九章9.1-9.3)

    在说明Lambda相关知识前,我们需要了解Lambda表达式常用于LINQ,那么我们来聊下LINQ. LINQ的基本功能就是创建操作管道,以及这些操作需要的任何状态.这些操作表示了各种关于数据的逻辑: ...

  4. words in view Moqui resource code

    annotation:注释 注解 documentation:文件  证明文件 embed:嵌入 context:环境  上下文 explicity: 明确的 明白的 conversion: 转化

  5. WampServer集成环境安装与配置

    实习到了第三个礼拜了,原来我们小组是以开发php为主的,我们项目的服务器也是用php做的,因此我觉得很有必要学一下php的相关知识,首先当然是搭建环境了,写篇博客分享下经验. 目录: 一.软件下载 二 ...

  6. Opentack常用技巧

    这篇博客将收集一些openstack里的使用技巧. 1. which dhcp agent is hosting the network?   2. 各个网桥port命令规则 grep for por ...

  7. 50行代码仿backbone_todos

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. fluery算法

    #include<stdio.h> #include<string.h> struct stack { int top; ]; }s; ][]; void dfs(int x) ...

  9. 【bzoj4010】 HNOI2015—菜肴制作

    http://www.lydsy.com/JudgeOnline/problem.php?id=4010 (题目链接) 题意 给出一张无向图要求出一个拓扑序列满足1的位置最靠前 ,在保证上面的条件下使 ...

  10. python TypeError: 'str' object does not support item assignment”

    想替换string里的空格,遍历替换提示如题错误,查询得知string类型不可更改 import string s = "2013/2/12" b = s.replace('/', ...