2

When I change the title of a UITabBarItem in a UITabBar programmatically from a UIViewController in another tab, the title changes correctly, but the image of the UITabBarItem changes its color to the tintColor or the tabbar.

Here is what is looks like after I set the title of the third tab within the UIViewController of the second tab like this

self.tabBarController?.tabBar.items![2].title = "9 Places"

After setting the title for the third tab

Any idea how I can prevent the third tab icon from changing the tint color?

Using Xcode 10.1 and iOS 12.1.1.

Thanks!

The Lone Coder
  • 3,062
  • 4
  • 20
  • 35
  • Can you provide more code? e.g. how you set `tabBar.tintColor`. – Mateusz Dec 14 '18 at 11:00
  • I am setting the tintColor generally with this `UINavigationBar.appearance().tintColor = App.Constant.keyColor` and `UIView.appearance().tintColor = App.Constant.keyColor` – The Lone Coder Dec 14 '18 at 12:21

2 Answers2

1

I think you will be better off setting the title and the image together.

self.tabBarItem = UITabBarItem(title: "9 Places", image: yourImage.withRenderingMode(.alwaysOriginal), selectedImage: yourImage)
Galo Torres Sevilla
  • 1,540
  • 2
  • 8
  • 15
0

The answer from @Gallo Torres Sevilla did not work for me, but it did point me in the right direction. So thanks for this.

Basically when setting up the UITabBarItem for the first time, I needed to supply the image including the renderingMode as suggested by Gallo as well as the selectedImage. Then subsequent changes to the title do not impact the tint.

The Lone Coder
  • 3,062
  • 4
  • 20
  • 35