0

I am looking to use the image's original color in the UITabBar when the image is selected, and default to the grey color when the image is not selected. I am trying to do this on the storyboard or in an elegant format instead of going to each viewDidLoad and manually pasting the line in several times. Any ideas would be great!

Ben Rockey
  • 920
  • 6
  • 23
AlexK
  • 336
  • 8
  • 21
  • 41
  • You could always create a subclass of `UIViewController` which is a parent to all your view controllers in which you can have this common code written only once. Personally I wouldn't even bother with tab bar though. As soon as you need some modification on it (which is usually the case) things get ugly and hackish. A stack view can hold your buttons or even custom views if you need them. – Matic Oblak May 24 '19 at 06:41

2 Answers2

0

Add two different image for single tabbar item in image assets. One is for the selected tab and another is for normal tab. Set the 'Render as' parameter to 'Original image' for both the image assets. Set normal image(when tab is not selected) to the 'Image' property for the Tab bar item and set the 'Selected Image' for the selected the image when tab bar item is selected.

enter image description here

Hope this helps.

BhargavR
  • 1,095
  • 7
  • 14
  • This will result in the same image duplicated throughout the code. I appreciate your effort though. – AlexK May 24 '19 at 06:47
0

You can set "Original Image" for Render Mode in Assets for that particular image.

enter image description here

  • The problem with this approach is that when the image should be 'greyed out' it will still display the original color, which is why I did not take this approach. – AlexK May 24 '19 at 09:46