swiftuiviewcontrolleruitabbaritemloadview

Get tab bar items in xcode to show in image original color as soon as the view is loaded


Morning ya'll. I've designed a tab bar and managed to customise it with custom tab bar items but i can't figure out how you get the tab bar items to load in their original picture color when view is loaded. My code looks like this:

class GamePage: UIViewController {



override func viewDidLoad() {

    super.viewDidLoad()

    tabBarItem.image = tabBarItem.image?.withRenderingMode(.alwaysOriginal)

             tabBarItem.selectedImage = tabBarItem.selectedImage?.withRenderingMode(.alwaysOriginal)

    

}

which gives this outcome: greyed our tab bar items

after clicking on the tab bar items i get the desired effect, but what i want is when the app launches and the first view is loaded to have the tab bar items in color like so: desired effect


Solution

  • You can set image rendering mode directly in Asset Catalog:

    enter image description here