Remove tab bar item text, show only image
Solution 1:
You should play with imageInsets
property of UITabBarItem
. Here is sample code:
let tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "more")
tabBarItem.imageInsets = UIEdgeInsets(top: 9, left: 0, bottom: -9, right: 0)
Values inside UIEdgeInsets
depend on your image size. Here is the result of that code in my app:
Solution 2:
// Remove the titles and adjust the inset to account for missing title
for(UITabBarItem * tabBarItem in self.tabBar.items){
tabBarItem.title = @"";
tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
}
Solution 3:
Here is how you do it in a storyboard.
Clear the title text, and set the image inset like the screenshot below
Remember the icon size should follow the apple design guideline
This means you should have 25px x 25px for @1x, 50px x 50px for @2x, 75px x 75px for @3x
Solution 4:
Using approach with setting each UITabBarItem
s title
property to ""
and update imageInsets
won't work properly if in view controller self.title
is set. For example if self.viewControllers
of UITabBarController are embedded in UINavigationController
and you need title to be displayed on navigation bar. In this case set UINavigationItem
s title directly using self.navigationItem.title
, not self.title
.
Solution 5:
If you're using storyboards this would be you best option. It loops through all of the tab bar items and for each one it sets the title to nothing and makes the image full screen. (You must have added an image in the storyboard)
for tabBarItem in tabBar.items!
{
tabBarItem.title = ""
tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0)
}