![](https://img-blog.csdnimg.cn/16ca6a18207642139f9352f74fbefea9.png)
if #available(iOS 15, *) {
let tabBarAppearance = UITabBarAppearance()
tabBarAppearance.backgroundColor = .white
tabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes = [.foregroundColor: UIColor.red]
tabBarAppearance.stackedLayoutAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.black]
tabBarAppearance.stackedLayoutAppearance.normal.iconColor = UIColor.black
tabBarAppearance.stackedLayoutAppearance.selected.iconColor = UIColor.red
tabBarView.standardAppearance = tabBarAppearance
tabBarView.scrollEdgeAppearance = tabBarAppearance
}
tintColor
: TabBarItem
's color.
barTintColor
: TabBar
's background bar's color.
unselectedItemTintColor
: color of unselected items.
修改ICON颜色
//Original image displayed as is
let imageView = UIImageView()
imageView.frame = CGRect(x: 50, y: 50, width: 200, height: 200)
imageView.contentMode = .scaleAspectFit
view.addSubview(imageView)
let myImageName = "apple_logo.png"
let myImage = UIImage(named: myImageName)
imageView.image = myImage
//Image now displayed in BLUE color as this is DEFAULT tint
let imageView2 = UIImageView()
imageView2.frame = CGRect(x: 300, y: 50, width: 200, height: 200)
imageView2.contentMode = .scaleAspectFit
view.addSubview(imageView2)
let myImageName2 = "apple_logo.png"
let myImage2 = UIImage(named: myImageName2)
imageView2.image = myImage2?.withRenderingMode(.alwaysTemplate)
//Image now displayed in RED color
let imageView3 = UIImageView()
imageView3.frame = CGRect(x: 550, y: 50, width: 200, height: 200)
imageView3.contentMode = .scaleAspectFit
view.addSubview(imageView3)
imageView3.image = myImage2?.withRenderingMode(.alwaysTemplate)
imageView3.tintColor = UIColor.red
![](https://img-blog.csdnimg.cn/05dc7b2975d24e1e8fecb20a809197f5.png)