1

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
abbood
  • 23,101
  • 16
  • 132
  • 246
  • 1
    Possible duplicate of [Moving UITabBarItem Image down?](https://stackoverflow.com/questions/16285205/moving-uitabbaritem-image-down) – Callam Dec 25 '18 at 14:11

2 Answers2

10

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

UITabBarItem.appearance().titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -10)
Callam
  • 11,409
  • 2
  • 34
  • 32
  • 1
    @Callarm i'm gonna have to respectfully ask you to change your name from _Callam_ to _Magician_ – abbood Dec 26 '18 at 17:46
1

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
Amer Hukic
  • 1,494
  • 1
  • 19
  • 29