How to provide normal state and selected/highlighted state images to uibarbuttonitem in iOS 7? Is there any way to provide tint colour for both normal and selected/highlighted state of uibarbuttonitem?
I don't want to use uibutton as a view for uibarbuttonitem! Any elegant solution would be highly appreciated.
According to this answer, I did something extra and kind of have an answer for you here. I have my custom UITabBarController, which is linked with my UITabBarController in the StoryBoard file. So in order to remove the automatic tint provided by iOS when the TabBar is unselected, I ended up removing it in this manner. The images can be a vast variety of images but just in the way recommended here. Here it goes:
So when moving from this tab to the other one and leaving this in the unselected (gray as default) tint, you can set it to the image provided. Thankfully, this works like a charm (:
You can do this using the UIAppearance Protocol Reference
You might also have to use:
Here is
Swift 4
solution:You can use a
UIButton
as acustomView
of aUIBarButtonItem
and have two different background images for anormal
andselected
state of the UIButton. Then when the button is tapped, you can just set theselected
state toYES
orNO
.Then your in method for when the button is clicked, change the state