导航--状态栏和导航栏颜色变化
2015-12-23 16:02
363 查看
导航上状态栏、控制栏的背景颜色和字体颜色
1.导航上控制栏和状态栏背景设置为同一颜色
[self.navigationController.navigationBarsetBarTintColor:[UIColororangeColor]];
2.导航上状态栏字体颜色设置
(1)
//设置状态栏显示内容的颜色是白色,在info.plist文件中添加View controller-based status bar appearance,设为NO
[[UIApplicationsharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];//该方法已舍弃,但是还能起作用
(2)在viewController通过preferredStatusBarStyle方法设置状态栏字体颜色
- (UIStatusBarStyle)preferredStatusBarStyle {
//设置为白色
return
UIStatusBarStyleLightContent;
}
如果viewController不是在 UINavgationController中,那么以上代码可以把状态栏文本颜色设置为白色,但是如果 viewController是添加到导航上的,你会发现上面代码达不到你想要的效果,状态栏文本颜色是黑色的!
这是为什么?
经过查找资料,才知道原来是这么一回事:
*UINavigationController不会将 preferredStatusBarStyle方法调用转给它的子视图,而是由它自己管理状态,而且它也应该那样做.因为UINavigationController 包含了它自己的状态栏
因此就算 UINavigationController中的viewController 实现了 preferredStatusBarStyle方法 也不会调用
那 UINavigationController是怎么决定 该返回 UIStatusBarStyleLightContent 还是 UIStatusBarStyleDefault的呢? 它是基于它的 UINavigationBar.barStyle属性.默认(UIBarStyleDefault)的是黑色文本的状态栏 而 UIBarStyleBlack是设置为白色文本的状态栏*
也就是说,如果viewController是在导航中的,想要改变状态栏文本颜色,那么需要通过代码:
另外,如果viewController在导航中,还想通过 preferredStatusBarStyle 方法设置状态栏文本颜色,那就只能隐藏导航栏了:
1.导航上控制栏和状态栏背景设置为同一颜色
[self.navigationController.navigationBarsetBarTintColor:[UIColororangeColor]];
2.导航上状态栏字体颜色设置
(1)
//设置状态栏显示内容的颜色是白色,在info.plist文件中添加View controller-based status bar appearance,设为NO
[[UIApplicationsharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];//该方法已舍弃,但是还能起作用
(2)在viewController通过preferredStatusBarStyle方法设置状态栏字体颜色
- (UIStatusBarStyle)preferredStatusBarStyle {
//设置为白色
return
UIStatusBarStyleLightContent;
}
如果viewController不是在 UINavgationController中,那么以上代码可以把状态栏文本颜色设置为白色,但是如果 viewController是添加到导航上的,你会发现上面代码达不到你想要的效果,状态栏文本颜色是黑色的!
这是为什么?
经过查找资料,才知道原来是这么一回事:
*UINavigationController不会将 preferredStatusBarStyle方法调用转给它的子视图,而是由它自己管理状态,而且它也应该那样做.因为UINavigationController 包含了它自己的状态栏
因此就算 UINavigationController中的viewController 实现了 preferredStatusBarStyle方法 也不会调用
那 UINavigationController是怎么决定 该返回 UIStatusBarStyleLightContent 还是 UIStatusBarStyleDefault的呢? 它是基于它的 UINavigationBar.barStyle属性.默认(UIBarStyleDefault)的是黑色文本的状态栏 而 UIBarStyleBlack是设置为白色文本的状态栏*
也就是说,如果viewController是在导航中的,想要改变状态栏文本颜色,那么需要通过代码:
<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">//将status bar 文本颜色设置为白色 self<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.navigationController</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.navigationBar</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.barStyle</span> = UIBarStyleBlack<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>
<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">//将status bar 文本颜色设置为黑色 ,默认就是黑色 self<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.navigationController</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.navigationBar</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.barStyle</span> = UIBarStyleDefault<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span></code& 4000 gt;<ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>
另外,如果viewController在导航中,还想通过 preferredStatusBarStyle 方法设置状态栏文本颜色,那就只能隐藏导航栏了:
<code class="hljs objectivec has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//隐藏导航栏后 系统会调用 preferredStatusBarStyle 方法</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">self</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.navigationController</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.navigationBarHidden</span> = <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">YES</span>;</code>
相关文章推荐
- jQuery实现下滑菜单导航效果代码
- jquery实现的仿天猫侧导航tab切换效果
- MFC对话框中添加状态栏的方法
- PHP的栏目导航程序
- jquery实现向下滑出的二级导航下滑菜单效果
- JS+CSS实现六级网站导航主菜单效果
- 状态栏 时间显示效果 数字钟
- JS实现网页顶部向下滑出的全国城市切换导航效果
- js实现显示当前状态的导航效果代码
- javascript实现当前页导航激活的方法
- JS实现来回出现文字的状态栏特效代码
- JS+CSS实现的日本门户网站经典选项卡导航效果
- JS实现自动变化的导航菜单效果代码
- jquery实现红色竖向多级向右展开的导航菜单效果
- jQuery实现的背景动态变化导航菜单效果
- 基于jquery固定于顶部的导航响应浏览器滚动条事件
- jquery动态导航插件dynamicNav用法实例分析
- jQuery+css实现的蓝色水平二级导航菜单效果代码
- jquery实现点击变换导航样式的方法
- jQuery ui实现动感的圆角渐变网站导航菜单效果代码