且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在iOS 7中更改导航栏颜色?

更新时间:2022-06-12 22:48:21

在iOS 7.0中,条形码的 tintColor 的行为已更改。它不再影响酒吧的背景。

The behavior of tintColor for bars has changed in iOS 7.0. It no longer affects the bar's background.

来自文档:

barTintColor Class Reference

应用于导航栏背景的色调颜色。

The tint color to apply to the navigation bar background.

@property(nonatomic, retain) UIColor *barTintColor

讨论
默认情况下,此颜色为半透明,除非您将半透明属性设置为

可用性

适用于iOS 7.0及更高版本。

Available in iOS 7.0 and later.

声明

UINavigationBar.h

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用户界面转换指南

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

EDIT Using xib