Tommy K Tommy K - 1 year ago 98
Swift Question

setting custom icons in tabbar for highlighted/not highlighted

I have icons in my assets that I want to use for my tab bar, 2 for each tab (one representing not highlighted i.e just an outline, and one representing highlighted i.e all filled in). The idea is to use the outlined icons for the tabs that aren't currently selected, and the filled in one for the tab that is currently selected. How can I go about doing this?

Answer Source

Just make an Class for your Tabbar, for example:

class MainTabBarController: UITabBarController {

     override func viewDidLoad() {

        for item in self.tabBar.items! as [UITabBarItem] {

        // loop through all of your elements in TabBar

        if let image = item.image {

            item.selectedImage = your Selected Image
            item.image = your base Image



You could store all your images in an Array containing UIImage, like:

let TabImages = [UIImage]()
let HighlightedImages = [UIImage]()

And then set them in your for each loop.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download