如何在不需要时摆脱 UIAppearance



在我的AppDelegate中,我使用UIAppearance使用以下代码设置自己的导航栏:

[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav5.png"] forBarMetrics:UIBarMetricsDefault];

但是我的应用程序的某些视图不需要它。我怎样才能摆脱它,这样我就可以只在相关视图中使用 IB?

您不需要使用代理。只需获取实际的导航栏,它应该看起来不同并直接在其上设置颜色。

[navigationBarInstance setTintColor:[UIColor blackColor]];
[navigationBarInstance setBackgroundImage:[UIImage imageNamed:@"nav5.png"] forBarMetrics:UIBarMetricsDefault];

您也可以将这两个值都设置为 nil ,您需要再次使用标准样式。(由Ben Clayton测试)。

[navigationBarInstance setTintColor:nil];
[navigationBarInstance setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

相关内容

最新更新