iOS 5中的UINavigationBar外观覆盖

adi*_*dit 5 iphone cocoa-touch objective-c ipad ios5

我有以下代码:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbarBackBlack.png"] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbarBackBlack.png"] forBarMetrics:UIBarMetricsLandscapePhone];
    [[UINavigationBar appearance] setTintColor:[UIColor colorWithWhite:0.72 alpha:1.0]];
Run Code Online (Sandbox Code Playgroud)

但是现在我希望在我的应用程序中有一个位置,我希望导航栏的颜色与我在整个应用程序中设置的这种通用颜色不同.如何仅针对此特定设置更改此设置.可能吗?

bry*_*mac 5

您也可以在导航栏的实例上调用setBackgroundImage.

看到这篇相关文章:

自定义UITabBar背景图像在iOS 5及更高版本中无效

您还应该根据它是否响应该选择器来调整它:

if ([navBar respondsToSelector:@selector(setBackgroundImage:)])
{
    [navBar setBackgroundImage:[UIImage imageNamed:@"tabbar_brn.jpg"]];
}
else
{
    // ios 4 code here
}
Run Code Online (Sandbox Code Playgroud)