当没有图像时,ios tabbar将文本放在中间

时间:2012-09-25 15:39:06

标签: objective-c ios5 uitabbar uitabbaritem

我的标签栏仅包含文字,没有图片 问题是文本总是显示在选项卡的底部,有没有办法将文本放在中间?

谢谢

3 个答案:

答案 0 :(得分:35)

知道了!

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

答案 1 :(得分:3)

补充,如果在tabBarController中设置多个viewControllers,则应使用以下内容:

for (UITabBarItem* item in tabBarController.tabBar.items)
{
    [item setTitlePositionAdjustment:UIOffsetMake(0, -10)];
}

答案 2 :(得分: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()