gpt4 book ai didi

ios - Swift - 无法更新 UITabBar barTintColor

转载 作者:可可西里 更新时间:2023-11-01 02:12:33 25 4
gpt4 key购买 nike

viewDidLoad 中,我尝试了以下方法来更新我的 UITabBar 的背景或“barTintColor”。我可以通过使用 [[UITabBar appearance] setBarTintColor:[UIColor blackColor]]; 用 objective-c 做到这一点。

我尝试过的:

    UITabBar.appearance().barTintColor = UIColor.white

self.navigationController?.navigationBar.barTintColor = UIColor.white;

UINavigationBar.appearance().barTintColor = UIColor.white

UINavigationBar.appearance().backgroundColor = UIColor.white

我想避免使用一些奇怪的 NSNotificationCenter 解决方案并从 AppDelegate 进行更新。为什么这在 Swift 中如此难以实现?将不胜感激。

最佳答案

注意:下面的方法应该在 Swift 3 中工作。下面的代码必须进入你的 viewDidLoad 才能工作。

方法一:

    tabBarController?.tabBar.barTintColor = UIColor.white
tabBarController?.tabBar.tintColor = UIColor.red
tabBarController?.tabBar.isTranslucent = false

输出:

enter image description here

方法二:

注意:我将 barTintColour 设置为绿色以显示这两种方法都有效..

    UITabBar.appearance().barTintColor = UIColor.green // Its strange why this method didn't worked for you?.Try updating your post with viewDidLoad.Its a better way to understand the issue.
UITabBar.appearance().tintColor = UIColor.purple

输出:

enter image description here

关于ios - Swift - 无法更新 UITabBar barTintColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40579961/

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