Can somebody tell me please how can I move title of UITabBarItem for example 2px to top?
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 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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With