如何确定设置UITabBar背景颜色和色调颜色

问题描述 投票:20回答:3

我已经尝试设置UITabBar的色调颜色和背景颜色已有相当长的一段时间了,似乎没有任何效果。到目前为止,我已经尝试过:

tabBarController?.tabBar.backgroundColor = UIColor.orangeColor()
tabBarController?.tabBar.barTintColor = UIColor.whiteColor()

以及:

UITabBar.appearance().tintColor = UIColor.orangeColor()

这些似乎都不会对我的标签栏产生任何影响。我还要提及的是,我将VC嵌入在导航控制器中,为此,我设置的全局色调很好用。

ios swift uitabbar
3个回答
41
投票

如果要隐式设置标签栏的tint and barTint color,则在Appdelegate.swift中,

    UITabBar.appearance().barTintColor = .orange
    UITabBar.appearance().tintColor = .green

如果要为特定的viewController设置标签栏的tint and barTint color,则在ViewController.swift中,

 self.tabBarController?.tabBar.tintColor = .orange
 self.tabBarController?.tabBar.barTintColor = .green

17
投票

设置标签栏背景色带有barTintColor

self.tabBar.barTintColor = UIColor.blueColor()
//or
UITabBar.appearance().barTintColor = UIColor.blueColor()

并且对于标签栏颜色:

self.tabBar.tintColor = UIColor.whiteColor() // Selected tab color
//or
UITabBar.appearance().tintColor = UIColor.whiteColor()

enter image description here


-2
投票

Swift 4+版本

UITabBar.appearance().barTintColor = UIColor.red
UITabBar.appearance().tintColor = UIColor.white
© www.soinside.com 2019 - 2024. All rights reserved.