gpt4 book ai didi

ios - 必须切换 View 才能让 "[[UINavigationBar appearance] setBarTintColor:[UIColor darkGrayColor]];"工作

转载 作者:行者123 更新时间:2023-11-29 03:08:49 24 4
gpt4 key购买 nike

我将条形色调设置为在单击按钮时不同,但您必须切换 View 才能使以下方法生效。我不知道为什么不是。

[[UINavigationBar appearance] setBarTintColor:[UIColor darkGrayColor]];

谢谢:D

最佳答案

The reason for the error:

[[UINavigationBar appearance] setBarTintColor:[UIColor
randomColor]];
doesn't work because the UIViewController has been initialized!!!

解决方法:

(1) UIAppearance用户在AppDelegate didFinishLaunch函数中设置全局效果。

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.

[[UINavigationBar appearance] setBarTintColor: [UIColor redColor]];
return YES;
}

(2) 关于初始化的 UIViewController ,你应该使用 self.navigationController.navigationBar 来设置颜色,这也会影响应用程序的生命周期。

[self.navigationController.navigationBar setBarTintColor:[UIColor randomColor]];

关于ios - 必须切换 View 才能让 "[[UINavigationBar appearance] setBarTintColor:[UIColor darkGrayColor]];"工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22450368/

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