You can use this Swift extension to define a new tabBarItemShowingOnlyImage() method that will return any UITabBarItem modified to display only the image:
// helper for creating an image-only UITabBarItem extension UITabBarItem { func tabBarItemShowingOnlyImage() -> UITabBarItem { // offset to center self.imageInsets = UIEdgeInsets(top:6,left:0,bottom:-6,right:0) // displace to hide self.setTitlePositionAdjustment(UIOffset(horizontal:0,vertical:30000)) return self } }
This extension is based on the tips suggested in other comments.
It hides the title, supplanting it, rather than setting it to nil , because sometimes other objects, such as the view controller itself, will set the title to some value after the tab bar item is initialized. It centers the image using imageInsets to compensate for its 6pt, the value I get is only from the eyeball on the iPhone 6 running iOS8.3.
I believe other devices and layout configurations may require a different offset correction, so the overall solution is likely to be more complex.
algal May 6 '15 at 17:35 2015-05-06 17:35
source share