如果我将代码放入 AppDelegate 的 DidFinishLaunchingWithOptions 函数中,我可以轻松更改选项卡栏的颜色,但如果我在 ViewController 中调用具有相同代码的函数,则它不会改变。例如,在 View Controller 中按下按钮后,如何让它发生变化?
这是 DidFinishLaunchingWithOptions 函数中的代码:
UITabBar.appearance().tintColor = UIColor.white
UITabBar.appearance().barTintColor = UIColor.black
最佳答案
使用appearance
代理为之后创建的任何新控件设置属性。它不会更改任何现有的相关控件。
如果您希望设置特定的现有实例的属性,请直接在控件上设置属性,而无需使用appearance
代理。
someTabBar.tintColor = UIColor.purple
someTabBar.barTintColor = UIColor.orange
关于swift - 应用加载后更改 TabBar 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42055132/