Search code examples
iosswiftuitabbaritem

Remove tab bar item text, show only image


Simple question, how can I remove the tab bar item text and show only the image?

I want the bar items to like in the instagram app:

enter image description here

In the inspector in xcode 6 I remove the title and choose a @2x (50px) and a @3x (75px) image. However the image does not use the free space of the removed text. Any ideas how to achieve the same tab bar item image like in the instagram app?


Solution

  • 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:

    enter image description here