Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center Tab Bar Icons Without Text in Swift

we're trying to center the tab bar icons to the tab bar center because we don't want to have the text below. So the icons should be alone and centered in the tab bar. This is how they look now. The tab bar controller is not the root viewcontroller, so we can't access it directly using rootviewcontroller as many responses we've found out there. Any ideas? We're turning crazy...

like image 880
Alex Martinez Avatar asked Mar 30 '15 21:03

Alex Martinez


1 Answers

To remove titletext, you can use code:

let tabBarItems = tabBar.items! as [UITabBarItem]
tabBarItems[0].title = nil

To get center of icon tabs, use this code

let tabBarItems = tabBar.items! as [UITabBarItem]
tabBarItems[0].imageInsets = UIEdgeInsetsMake(6,0,-6,0)

for complete code remove titletext and get center icon

let tabBarItems = tabBar.items! as [UITabBarItem]
tabBarItems[0].title = nil
tabBarItems[0].imageInsets = UIEdgeInsetsMake(6,0,-6,0)
like image 191
Agus Cahyono Avatar answered Oct 24 '22 23:10

Agus Cahyono