如何definitiveley设置UITabBar背景颜色和UITabBar色彩

Har*_*zin 17 uitabbar ios swift

我一直试图将UITabBar的色彩和背景颜色设置好一段时间,似乎没有任何效果.到目前为止,我尝试过:

tabBarController?.tabBar.backgroundColor = UIColor.orangeColor()
tabBarController?.tabBar.barTintColor = UIColor.whiteColor()
Run Code Online (Sandbox Code Playgroud)

以及:

UITabBar.appearance().tintColor = UIColor.orangeColor()
Run Code Online (Sandbox Code Playgroud)

这些似乎都没有对我的标签栏产生任何影响.我还想提一下,我将VC嵌入到导航控制器中,我设置的全局色调颜色完全正常.

Lio*_*ion 40

如果你想tint and barTint color隐式设置tabbar 然后在你的Appdelegate.swift,

    UITabBar.appearance().barTintColor = .orange
    UITabBar.appearance().tintColor = .green
Run Code Online (Sandbox Code Playgroud)

如果你想tint and barTint color为特定的viewController 设置tabbar ,那么ViewController.swift,

 self.tabBarController?.tabBar.tintColor = .orange
 self.tabBarController?.tabBar.barTintColor = .green
Run Code Online (Sandbox Code Playgroud)

  • 嗨@Lion,这个`UITabBar.appearance().barTintColor`中不存在barTintColor? (2认同)
  • @Khuong它就在那里,只是Xcode完全拒绝在自动完成选项中显示它 (2认同)

Pus*_*hpa 17

使用barTintColor设置标签栏背景颜色:

self.tabBar.barTintColor = UIColor.blueColor()
//or
UITabBar.appearance().barTintColor = UIColor.blueColor()
Run Code Online (Sandbox Code Playgroud)

对于标签栏色调颜色:

self.tabBar.tintColor = UIColor.whiteColor() // Selected tab color
//or
UITabBar.appearance().tintColor = UIColor.whiteColor()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述