0

I want to set my tab bar to have custom images but XCode insists in leaving the space for the tab bar item title text leaving my images positioned too high in the tab bar. I've tried the following code in my TabBarController.swift viewDidLoad function:

let tabItems = tabBar.items as [UITabBarItem]
     tabItems[0].title = nil
    tabItems[0].selectedImage = UIImage(named: "HomeWhiteIcon")
    tabItems[1].title = "Database"
    tabItems[1].selectedImage = UIImage(named: "Second")
    tabItems[2].title = nil
    tabItems[2].selectedImage = UIImage(named: "SettingsWhiteIcon")
    tabItems[3].title = nil
    tabItems[3].selectedImage = UIImage(named: "ReportsWhiteIcon")

However, although no title is displayed the images are positioned too high as pic below (please ignore database icon - I have not set this icon yet.

tab bar images

Tom
  • 790
  • 2
  • 9
  • 32

1 Answers1

0

Here's a random stab as swift is not my strong suit, but perhaps the database icon having a title is causing the entire title row to not collapse. Try removing the title from the database icon.

Otherwise have you seen the setTitlePositionAdjustment method? Perhaps adjust the title's position up into the icon and the space below will go away.

Clukester
  • 132
  • 1
  • 8
  • Interesting - when I removed the database title from the storyboard and performed a project clean, the database title still shows up. – Tom Jan 08 '15 at 21:46
  • My mistake - I still had it programmed in my tabBarViewController. Yes, your suggestion appears to work if I also apply an image inset. It seems a crude workaround. I wonder if we're missing something? – Tom Jan 08 '15 at 21:50
  • Actually, adjusting the insets seems to be an accepted way to go: http://stackoverflow.com/a/16568865/1828107 – Clukester Jan 09 '15 at 14:36