iOS 5:您可以覆盖特定类中的UIAppearance自定义吗? [英] iOS 5: Can you override UIAppearance customisations in specific classes?
问题描述
我正在构建一个包含许多视图控制器的应用程序:我有一个 UITabBarController
,它包含4 UINavigationController
。我希望所有导航栏都是我的自定义颜色,比如蓝色,我通过在我的应用委托中执行此操作来实现:
I'm building an app with many view controllers: I have a UITabBarController
which holds 4 UINavigationController
. I want all the nav bars to be my custom color, say blue, which I achieve by doing this in my app delegate:
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
但是我还有一个特殊的视图控制器,它有一个地图,对于这个视图控制器,我想要使用 UIAppearance
覆盖蓝色导航栏设置,使其成为黑色不透明样式。我试过在 viewDidLoad
中调用它:
But I also have one special view controller which has a map, and for this view controller I want to override the blue navbar set using UIAppearance
to make it the black opaque style. I've tried by calling this inside viewDidLoad
:
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.translucent = YES;
但没有任何反应。可以这样做还是我必须放弃UIAppearance并为每个视图控制器手动设置 navigationBar
的属性?
But nothing happens. Can this be done or do I have to abandon UIAppearance and set the properties on navigationBar
manually for each view controller?
推荐答案
你做这件事的方式应该有效,但事实并非如此。这确实有效:
The way you are doing it is supposed to work, but it doesn't. This does work though:
UINavigationBar.appearance(whenContainedInInstancesOf: [YourOtherVC.self]).tintColor = .black
Objective-C
Objective-C
[[UINavigationBar appearanceWhenContainedIn:[YourOtherVC class], nil] setTintColor:[UIColor blackColor]];
这篇关于iOS 5:您可以覆盖特定类中的UIAppearance自定义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!