如何减少 UITabBarItem 图像和文本之间的垂直填充?

How to decrease vertical padding between UITabBarItem image and text?

我想减少 UITabBarItem 与其文本之间的垂直填充:

ie 为了使它看起来像这样:

我试过这段代码:

    let pStyle = NSMutableParagraphStyle()
    pStyle.lineSpacing = -10.0
    UITabBarItem.appearance().setTitleTextAttributes([.paragraphStyle: pStyle], for: .normal)

但是没用。想法?

用偏移量调整标签栏项目标题的位置。

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

所选答案适用于 iOS 15。对于 iOS 15 及更高版本,我们必须使用 UITabBarAppearance:

设置标题位置调整
let appearance = UITabBarAppearance()
appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -10)
tabBar.standardAppearance = appearance
tabBar.scrollEdgeAppearance = appearance