在iOS中为不同的UIViewController设置不同的UINavigatiobar颜色?

在iOS中为不同的UIViewController设置不同的UINavigatiobar颜色?,ios,objective-c,uinavigationcontroller,Ios,Objective C,Uinavigationcontroller,我有一个带有3个UIViewController的示例项目,我想为每个Viewcontroller更改UINavigationbar颜色 我尝试在ViewDidAppear方法中使用此代码,但它没有改变 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed: @"bg.png"] forBarMetr

我有一个带有3个UIViewController的示例项目,我想为每个Viewcontroller更改UINavigationbar颜色

我尝试在ViewDidAppear方法中使用此代码,但它没有改变

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed: @"bg.png"]
                                              forBarMetrics:UIBarMetricsDefault];

事实上,您的代码是为navigationBar设置背景的,这是真的。但如果要为每个Viewcontroller导航栏设置颜色,请在ViewController1中说出第一个view controller ViewDidDisplay方法add

[self.navigationController.navigationBar setBarTintColor:[UIColor greenColor]];
[self.navigationController.navigationBar setBarTintColor:[UIColor blueColor]];
在ViewController2中,说出第二个视图控制器ViewDidDisplay方法add

[self.navigationController.navigationBar setBarTintColor:[UIColor greenColor]];
[self.navigationController.navigationBar setBarTintColor:[UIColor blueColor]];
然后通过这些控制器导航,您将看到导航栏的背景颜色将发生变化

但您的问题可能不是设置ViewController自定义类,您可以从identity inspector进行设置