Question or problem in the Swift programming language:
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…
How to solve the problem:
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)