1

I have 3 TabBarItems in my ViewController One of them is default when screen loaded. But it is not highlighted I am trying to highlight it manually

verride func viewDidLoad() {
        super.viewDidLoad()

        if let items = self.TabBar.items as? [UITabBarItem]? {
            let button = items![1]
            button.image = button.image?.tabBarImageWithCustomTint(UIColor.redColor())
        }

I am getting an error that "Value of type UIImage has no member tabBarImageWithCustomTint" Any suggestions?

Yaroslav Dukal
  • 3,894
  • 29
  • 36

2 Answers2

0

I believe you have to do:

button.image?.tabBarImageWithCustomTint = UIColor.redColor()
  • Never mind have a look at Nick Wargnier comment on this post: http://stackoverflow.com/questions/19829356/color-tint-uibutton-image He explains how to change the tint color of an image on a button. –  Dec 22 '15 at 08:20
  • 1
    decided to change tabBarItem to regular Button – Yaroslav Dukal Dec 22 '15 at 08:29
0

There are two options to set mode for images. Here i am explaining using ImageAssets

Step 1: Add image to ImageAssets.

Step 2: Set the Render As to Template Image from attribute inspector

See screenshot:

enter image description here

And keep the same code which you have done already.

Suraj Sonawane
  • 2,044
  • 1
  • 14
  • 24