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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)