ios - 更改导航栏ios6和ios7的颜色

标签 ios iphone objective-c uinavigationbar

我正在将应用程序升级到iOS7。但是我也想保留iOS6界面。除导航栏外,它运行良好。在iOS7中,它们看起来很棒(只是默认颜色,其半透明属性为YES。在iOS6中,导航栏显示为默认蓝色条,我希望它们是黑色半透明的。

我要做的是检查iOS版本,然后执行一些代码。在调试器中,我在vComp变量中看到它们的版本正确,但是颜色没有改变。不用介意redColor属性,这只是用于测试。两种方式都为我提供默认颜色。

这是我的代码:

- (void) fixNavBarColor:(UINavigationBar*)bar {
    NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
    if ([[vComp objectAtIndex:0] intValue] >= 7) {
        bar.barTintColor = [UIColor redColor];
        bar.translucent = NO;
    }
    else {
        bar.tintColor = [UIColor redColor];
        bar.opaque = YES;
    }
}

没有错误或警告。
有任何想法吗?

最佳答案

您不应该将tintColor直接设置为navigationBar,因为它不会被应用到应用程序的其他部分,而应该使用UINavigationBar的外观来设置tintColor,iOS 5.0及更高版本可以使用。

    [[UINavigationBar appearance] setTintColor:"Your Color"];

关于ios - 更改导航栏ios6和ios7的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20920915/

相关文章:

ios - 发电机 ios

iphone - 为什么在 iOS5 中用中文创建 framesetter 非常慢

ios - 在 ScrollView 中加载非常大的图像以进行缩放的最佳实践?

javascript - Vimeo 不响应 iOS 应用程序中的 Javascript

objective-c - NSFetchedResultsController 不调用 controllerDidChangeContent : after update to non-fetched NSManagedObject

iphone - "The binary you uploaded was invalid. the file was not a valid zip file"将应用程序上传到 iTunes Connect 时出现错误消息

iphone - 导航 Controller 中未使用的 View 会怎样?

iphone - 模拟器中的核心位置问题

ios - 使用transitionStyle .scroll时如何将UIPageViewControllerSpineLocation设置为.mid

iphone - 如何设置多个文件播放器音频单元同时启动?