在 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
输出:
方法二:
注意:我将 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
输出:
关于ios - Swift - 无法更新 UITabBar barTintColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40579961/