我的标签栏只包含文本,没有图像。
问题是文本总是显示在选项卡的底部,有没有办法将文本定位在中间?
谢谢
知道了!
[tab.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -10)]
补充一下,如果你在 tabBarController 中设置了 multi viewControllers,你应该使用如下:
for (UITabBarItem* item in tabBarController.tabBar.items)
{
[item setTitlePositionAdjustment:UIOffsetMake(0, -10)];
}
快速更新。
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
}
// 例如
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()