Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move title of UITabBarItem?

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

like image 508
iWizard Avatar asked May 04 '12 11:05

iWizard


3 Answers

Solution:

UITabBarItem *item = [tabBar.items objectAtIndex:0]; 
item.titlePositionAdjustment = UIOffsetMake(0, -5.0);
like image 109
iWizard Avatar answered Nov 19 '22 00:11

iWizard


Update for Swift 3

Put this code inside UITabBarController:

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

Credit goes to Tim Brown

like image 22
Ibrahim Avatar answered Nov 19 '22 00:11

Ibrahim


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 
    } 
like image 1
Iraniya Naynesh Avatar answered Nov 19 '22 00:11

Iraniya Naynesh