ios tabbar put text in the middle when no image

醉酒当歌 提交于 2019-11-30 01:49:15

问题


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


回答1:


Got it!

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




回答2:


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)];
}



回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!