如何更改iOS6和iOS7中導航欄的背景顏色?我想知道何時使用setBarTintColor:
方法以及何時使用backgroundColor
更改導航欄的背景顏色。如何更改ios6和ios7中導航欄的背景顏色?
請告訴我這兩種方法的區別。
另一種方法是在ios6和ios7中更改導航欄的背景顏色。
謝謝!
如何更改iOS6和iOS7中導航欄的背景顏色?我想知道何時使用setBarTintColor:
方法以及何時使用backgroundColor
更改導航欄的背景顏色。如何更改ios6和ios7中導航欄的背景顏色?
請告訴我這兩種方法的區別。
另一種方法是在ios6和ios7中更改導航欄的背景顏色。
謝謝!
self.navigationBar.barTintColor = [UIColor blueColor];
self.navigationBar.tintColor = [UIColor whiteColor];
self.navigationBar.translucent = NO;
// barTintColor設置背景顏色 // tintColor設置按鈕顏色
試試這個...我refered這link它支持兩種iOS6的和iOS7
// Uncomment to change the background color of navigation bar
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];
// Uncomment to change the color of back button
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// Uncomment to assign a custom backgroung image
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg_ios7.png"] forBarMetrics:UIBarMetricsDefault];
// Uncomment to change the back indicator image
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"back_btn.png"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back_btn.png"]];
// Uncomment to change the font style of the title
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
in ios6
[[UINavigationBar appearance] setBackgroundColor:[UIColor redColor]];
在ios7
navigationController.navigationBar.barTintColor = [UIColor greenColor];
或
[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];
barTintColor
=適用於導航欄背景。這個只適用於iOS 7.對於iOS 6,您可以使用tintColor。
tintColor
=適用於導航項目和欄按鈕項目。
可以使用
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];
}
或
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;
}
}