更改导航栏ios6和ios7的颜色

A3O

我正在将我的应用程序升级到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"];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章