How to move title of UITabBarItem? How to move title of UITabBarItem? xcode xcode

How to move title of UITabBarItem?


Solution:

UITabBarItem *item = [tabBar.items objectAtIndex:0]; item.titlePositionAdjustment = UIOffsetMake(0, -5.0);


Update for Swift 3

Put this code inside UITabBarController:

UITabBarItem.appearance().titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -5)

Credit goes to Tim Brown


Swift 4Like 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     }