Remove Icons from TabBar

I have deployed UITabBarViewController & I have populated 3 Tabs with different ViewControllers.


I want to remove Icons from TabBar & want to keep just Text. Make text center allgn Vertically in TabBar.


I currently naming Tabs like this in viewDidLoad:


self.tabBarController?.tabBar.items?[0].title = "tab 1"
self.tabBarController?.tabBar.items?[1].title = "tab 2"
self.tabBarController?.tabBar.items?[2].title = "tab 3"

Here is how I did it :


In each viewController, declare the tabBarItem as custom, no selected image.

Declare an IBOutlet for the item:

    @IBOutlet weak var tabBarItem1: UITabBarItem!

In viewDidLoad, set the text style:

        tabBarItem1.setTitleTextAttributes([NSAttributedStringKey.font: UIFont(name: "Arial", size: 20)], for: .normal)


I've not found how to align vertically, except with a trick:

- delete title in IB

- create an image that contains the former title "tab 1"

Can you let me know how to declare programatically TabBarItem as custom with no selected image?

In the view, select the tabBarItem (eg item1).

Go to Attributes inspector in IB

In Tab Bar Item area, in nsystem item, select Custom

In Bar Item area, where the title is:

Leave selected image empty, or choose the image with the text of the label if you want to use the trick I proposed.

clear the title if you don't want to see, or keep it if you want to change font only.


Now, to access to this item programmatically :

In the view, where you see one icon in the tab bar at the bottom, control drag from this icon to the controller code: that creates the IBOutlet.

Did it work ?

No I changed my mind...

OK. So please, just close the thread. And good luck.

Remove Icons from TabBar
 
 
Q