Reputation: 23548
I would like to decrease the vertical padding between the UITabBarItem and its text:
ie in order to make it look like this:
I tried this code:
let pStyle = NSMutableParagraphStyle()
pStyle.lineSpacing = -10.0
UITabBarItem.appearance().setTitleTextAttributes([.paragraphStyle: pStyle], for: .normal)
but it didn't work. Ideas?
Upvotes: 1
Views: 3856
Reputation: 1524
The selected answer works for until iOS 15. For iOS 15 and later we have to set the title position adjustment using UITabBarAppearance
:
let appearance = UITabBarAppearance()
appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -10)
tabBar.standardAppearance = appearance
tabBar.scrollEdgeAppearance = appearance
Upvotes: 1
Reputation: 11539
Adjust the position of the tab bar item title with an offset.
UITabBarItem.appearance().titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -10)
Upvotes: 12