gpt4 book ai didi

ios - UINavigationBar 自定义背景图像应用于一个 View Controller ,然后影响应用程序中的每个 View Controller

转载 作者:行者123 更新时间:2023-12-01 18:15:25 24 4
gpt4 key购买 nike

我正在我的应用程序中使用主题。每个主题都带有一个自定义导航栏。默认情况下,我在 AppDelegate 中应用了自定义导航栏:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
UIImage *navBackgroundImage = [UIImage imageNamed:@"purplynav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];

如果我在我的应用程序和 viewWillAppear 中转到特定的 TableView Controller ,我会输入:
if ([self.selectedTheme isEqualToString:@"Blur"])
{
UIImage *navBackgroundImage = [UIImage imageNamed:@"pastelpinknav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
}

“pastelpinknav”突然被应用到我的应用程序中的每一个导航栏,即使我只是在这个 TableView Controller 中设置它。

如何设置它以便导航栏在设置时仅适用于这个 View Controller ,但在未设置主题时仍设置为 App Delegate 中的默认值?

提前致谢!

最佳答案

您必须再次更改 viewWillDisappear 中的导航栏图像

UIImage *navBackgroundImage = [UIImage imageNamed:@"purplynav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];

因为您使用的是 [UINavigationBar appearance]它通常会更改 UINavigationBar外貌。

关于ios - UINavigationBar 自定义背景图像应用于一个 View Controller ,然后影响应用程序中的每个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22479547/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com