14

我的标签栏只包含文本,没有图像。
问题是文本总是显示在选项卡的底部,有没有办法将文本定位在中间?

谢谢

4

3 回答 3

37

知道了!

[tab.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -10)]

于 2012-09-27T10:34:07.860 回答
5

补充一下,如果你在 tabBarController 中设置了 multi viewControllers,你应该使用如下:

for (UITabBarItem* item in tabBarController.tabBar.items)
{
    [item setTitlePositionAdjustment:UIOffsetMake(0, -10)];
}
于 2015-04-01T03:12:26.620 回答
0

快速更新。

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()
于 2017-09-20T18:42:17.637 回答