简体   繁体   中英

Change image tint, title tint, background and so on in new UITabbar from iOS 13

I faced a weird problem. I wanted to change the colors of my tabBar in just one of my view controllers of my tabBar. How do I achieve this in iOS > 13?

After searching a lot and finding no working solutions, I succeeded by luck. I found out that you must set an appearance object before I can change them!! But if you set appearance before the override function endAppearanceTransition() of UITabbar it is working, but not anymore. finally, this way worked:

  1. Set an empty appearance object at viewDidLoad of one of the view Controllers or UITabbarViewcontroller to be executed one time:

     override func viewDidLoad() { super.viewDidLoad() tabBarController?.tabBar.standardAppearance = UITabBarAppearance() }
  2. Then you can use updating like this at anytime:

     let attrs = [NSAttributedString.Key.foregroundColor: UIColor.green] tabBarController?.tabBar.backgroundColor = barColor tabBarController?.tabBar.standardAppearance.stackedLayoutAppearance.selected.iconColor =.green tabBarController?.tabBar.standardAppearance.stackedLayoutAppearance.normal.iconColor =.green tabBarController?.tabBar.standardAppearance.stackedLayoutAppearance.normal.titleTextAttributes = attrs tabBarController?.tabBar.standardAppearance.stackedLayoutAppearance.selected.titleTextAttributes = attrs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM