My tabbar consists only of text, no images.
The problem is that the text always show on the bottom of the tab, is there a way to position the text in the middle ?
Thank you
Got it!
[tab.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -10)]
A supplement, if you set multi viewControllers in tabBarController, you should use the following:
for (UITabBarItem* item in tabBarController.tabBar.items)
{
[item setTitlePositionAdjustment:UIOffsetMake(0, -10)];
}
swift update.
func tabBarItem(title: String, imageName: String, selectedImageName: String, tagIndex: Int) -> UITabBarItem {
let item = UITabBarItem(title: title,
image: UIImage(named: imageName),
selectedImage: UIImage(named: selectedImageName))
item.titlePositionAdjustment = UIOffset(horizontal:0, vertical:-10)
item.tag = tagIndex
return item
}
// For example
let window = UIWindow.window()
let vc = UIViewController()
vc.tabBarItem = tabBarItem(title: "More", imageName: "icon_more", selectedImageName: "icon_more", tagIndex: 1)
let mainTBC = UITabBarController()
mainTBC.viewControllers = [vc]
window?.rootViewController = mainTBC
window?.makeKeyAndVisible()
来源:https://stackoverflow.com/questions/12586411/ios-tabbar-put-text-in-the-middle-when-no-image