navigationBar.barTintColor始终为黑色,无法更改它

时间:2014-04-03 13:04:19

标签: ios iphone cocoa-touch

我的应用中的navigationBar.barTintColor始终是黑色的,我无法更改它。我检查了所有课程,但我从未将其设置为黑色,但我将其设置为UIColor clearColor。酒吧仍然是黑色的。有什么建议吗?
编辑:我发现问题出在我的[UIColor clearColor]上,当我将其更改为任何其他颜色时,它会改变颜色,但应该是clearColor让它看起来很黑。

4 个答案:

答案 0 :(得分:2)

如果其IOS7尝试以下代码

[[UINavigationBar appearance]setBarTintColor: [<Specify the UIColor you want>];

在IOS6中试试这个

[[UINavigationBar appearance] setTintColor: [<Specify the UIColor you want>];

编辑:

我认为你已经给出了

self.navigationController.navigationBar.barTintColor = [UIColor clearColor];

这会产生黑色。如果您想要任何特定的色调,必须在清除后指定

self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
self.navigationController.navigationBar.barTintColor = [UIColor <specify your color>];

答案 1 :(得分:1)

看看那里

enter image description here

尝试修改导航栏上的StyleTranslucent属性(图片右上角)。

如果您在修改状态栏颜色时遇到问题,请尝试将其添加到.plist(下面一行)。

enter image description here

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

最后,这里有一些您可能需要的代码。

// Status bar color
[[UIApplication sharedApplication] setStatusBarStyle:yourStyle];

// Navigation bars color
[UINavigationBar appearance].barStyle = yourStyle;
[UINavigationBar appearance].barTintColor = [UIColor yourColor];

// Navigation bars items color
[UINavigationBar appearance].tintColor = [UIColor yourColor];

答案 2 :(得分:0)

if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
{
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];

    [[UINavigationBar appearance] setTitleTextAttributes:
     @{
       UITextAttributeTextColor: [UIColor whiteColor],UITextAttributeTextShadowColor: [UIColor clearColor],UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],UITextAttributeFont: [UIFont fontWithName:@"ArialMT" size:18.0f]
       }];


    CGFloat verticalOffset = -4;
    [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
}
else
{
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];

    // 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:@""]];
    [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@""]];

    // 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:@"ArialMT" size:18.0], NSFontAttributeName, nil]];

    CGFloat verticalOffset = -4;
    [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
}

答案 3 :(得分:0)

在iOS 7中尝试:

[self.navigationController.navigationBar setTranslucent:NO];