Reputation: 1363
I am trying to change the default grey colour of the unselected UITabBarItems. I have managed to change the text but not the image.
TabBar.appearance().barTintColor = UIColor(red: 86.0/255.0, green: 132.0/255.0, blue: 208.0/255.0, alpha: 1.0)
var normalTint: UIColor = UIColor.whiteColor()
TabBar.appearance().tintColor = UIColor.whiteColor()
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: normalTint,NSFontAttributeName: UIFont(name: "Arial", size: 13)!], forState: UIControlState.Normal)
Upvotes: 3
Views: 5668
Reputation: 737
func styleTabBar(){
let fontAttributes = [NSAttributedString.Key.foregroundColor: UIColor.gray, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 10.0)]
let selectedFontAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 10.0)]
if #available(iOS 13.0, *) {
let tabBarAppearance = UITabBarAppearance()
let tabBarItemAppearance = UITabBarItemAppearance()
tabBarItemAppearance.normal.iconColor = UIColor.gray
tabBarItemAppearance.selected.iconColor = UIColor.red
tabBarItemAppearance.normal.titleTextAttributes = fontAttributes
tabBarItemAppearance.selected.titleTextAttributes = selectedFontAttributes
tabBarAppearance.configureWithOpaqueBackground()
tabBarAppearance.backgroundColor = UIColor.white
tabBarAppearance.stackedLayoutAppearance = tabBarItemAppearance
UITabBar.appearance().standardAppearance = tabBarAppearance
if #available(iOS 15.0, *) {
UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
}
}else{
UITabBar.appearance().barTintColor = UIColor.white
UITabBar.appearance().tintColor = UIColor.gray
UITabBar.appearance().unselectedItemTintColor = UIColor.red
UITabBarItem.appearance().setTitleTextAttributes(fontAttributes, for: .normal)
UITabBarItem.appearance().setTitleTextAttributes(selectedFontAttributes, for: .selected)
}
}
Upvotes: 0
Reputation: 1161
Upvotes: 3
Reputation: 11650
iOS 10 | Swift 3
class TabBarVC: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
// make unselected icons white
self.tabBar.unselectedItemTintColor = UIColor.white
}
}
Upvotes: 15
Reputation: 7013
you can use .AlwaysOriginal
tabBarItem.selectedImage = UIImage(named: "first-selected")!.imageWithRenderingMode(.AlwaysOriginal)
Upvotes: 4