How to move title of UITabBarItem?

后端 未结 5 2101
长发绾君心
长发绾君心 2021-02-13 04:08

Can somebody tell me please how can I move title of UITabBarItem for example 2px to top?

5条回答
  •  孤街浪徒
    2021-02-13 04:47

    Swift 4 Like me, if you are creating tab bar controller inside some other controller just after adding all controller you can loop through the tab bar items and change title and positioning and font

    for (index,tabBarItem) in tabBarController.tabBar.items!.enumerated() {
            tabBarItem.image = nil //if you only want title and no Image
            tabBarItem.title = titleArray[index] //setting your title based on some array
            let attributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20)] // changeing font and height of the text
            tabBarItem.setTitleTextAttributes(attributes, for: .normal)
            tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -10.0) // updating the title positon 
        } 
    

提交回复
热议问题