abbood
abbood

Reputation: 23548

How to decrease vertical padding between UITabBarItem image and text?

I would like to decrease the vertical padding between the UITabBarItem and its text:

enter image description here

ie in order to make it look like this:

enter image description here

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

Answers (2)

Amer Hukic
Amer Hukic

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

Callam
Callam

Reputation: 11539

Adjust the position of the tab bar item title with an offset.

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

Upvotes: 12

Related Questions