
这是我打算放在屏幕上的自定义标签栏。但是,我的伙伴希望文本稍微向上。我该怎么做?
为什么不为视图控制器设置一个空的标题属性并将标题添加到选项卡的自定义图像中?
更新:为了回答的完整性;没有图像时,来自评论和ios 标签栏将文本放在中间
[tab.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -10)]
你可能想在全球范围内应用这个偏移量,所以我建议
对象-C
[UITabBarItem appearance].titlePositionAdjustment = UIOffsetMake(0, -4);
迅速:
UITabBarItem.appearance().titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -4)
您可以直接从 Interface Builder(标题位置的自定义偏移量)中执行此操作,如下所示:

对于 iOS 13 及更高版本:
if #available(iOS 13, *) {
let appearance = UITabBarAppearance()
appearance.stackedLayoutAppearance.selected.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -10)
appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -10)
}
我在这里找到了答案:ios tabbar put text in the middle when no image will try this one and see how it goes :)
更新:它有效。只有 1 行代码。