如何在 iOS 7 中更改导航栏颜色? [英] How to change Navigation Bar color in iOS 7?
问题描述
如何在 iOS 7 中更改导航栏颜色?
How do I change the Navigation Bar color in iOS 7?
基本上我想实现类似 Twitter Nav Bar 的东西(更新 Twitter for iOS7
就是这样).我在 view controller
顶部嵌入了一个导航栏.我想要的只是将导航栏颜色与顶部的实用程序栏一起更改为浅蓝色.我似乎在 storyboard
中找不到选项.
Basically I want to achieve something like the Twitter Nav Bar (updated Twitter for iOS7
that is). I embedded-in a nav bar atop a view controller
. All I want is to change the nav bar color to light blue along with the utility bar at the top. I can't seem to find an option in my storyboard
.
推荐答案
tintColor
对条形的行为在 iOS 7.0 中发生了变化.它不再影响栏的背景.
The behavior of tintColor
for bars has changed in iOS 7.0. It no longer affects the bar's background.
来自文档:
barTintColor 类参考
应用于导航栏背景的色调.
The tint color to apply to the navigation bar background.
@property(nonatomic, retain) UIColor *barTintColor
讨论
除非您将 translucent 属性设置为 NO
,否则此颜色默认为半透明.
Discussion
This color is made translucent by default unless you set the translucent property to NO
.
可用性
适用于 iOS 7.0 及更高版本.
Available in iOS 7.0 and later.
NSArray *ver = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ([[ver objectAtIndex:0] intValue] >= 7) {
// iOS 7.0 or later
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
self.navigationController.navigationBar.translucent = NO;
}else {
// iOS 6.1 or earlier
self.navigationController.navigationBar.tintColor = [UIColor redColor];
}
我们也可以使用它来检查 iOS 版本,如 iOS 7 UI 过渡指南
We can also use this to check iOS Version as mention in iOS 7 UI Transition Guide
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// iOS 6.1 or earlier
self.navigationController.navigationBar.tintColor = [UIColor redColor];
} else {
// iOS 7.0 or later
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
self.navigationController.navigationBar.translucent = NO;
}
编辑使用 xib
这篇关于如何在 iOS 7 中更改导航栏颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!