繁体   English   中英

更改UINavigationBar的背景颜色

[英]Change the background color of UINavigationBar

我想更改UINvaigationBar的背景颜色,并且使用了tintColor属性,但它没有更改颜色。 您可以在下面查看代码。

在我的Appdelegate中,我创建一个UITabBarController

tabbar = [[UITabBarController alloc] init];

然后我创建一个UINavigationController并将我的UITableViewController附加到它

UINavigationController *myNavigation = [[UINavigationController alloc] initWithRootViewController:myViewController];

然后像这样将UINavigationControllers附加到我的标签栏

[tabbar setViewControllers:viewControllers]; //viewControllers is an array of UINavigationControllers

我试图像这样在myAppdelegate中设置属性tintColor

[[myNavigation navigationBar] setTintColor:[UIColor redColor]];

但这没有按预期工作,因此我在ViewController中尝试了相同的操作

 - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        [self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
        self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
        self.navigationItem.title = @"Test";
    }

仍然没有任何反应。 请查看下面的图片,以查看导航栏现在的外观。

在此处输入图片说明

感谢您的帮助。

干杯

作为一种变通办法,您可以在色彩的位置使用图像,请检查以下代码是否相同。

if ([myNavigation respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
        [myNavigation setBackgroundImage:[UIImage imageNamed:BAR_IMAGE_NAME] forbarMetrics:UIBarMetricsDefault];
    }else {
        [myNavigation insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:BAR_IMAGE_NAME]] autorelease]  atIndex:0];
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM