这是我打算放在屏幕上的自定义标签栏。但是,我的伙伴希望文本稍微向上。我该怎么做?
问问题
25870 次
6 回答
53
为什么不为视图控制器设置一个空的标题属性并将标题添加到选项卡的自定义图像中?
更新:为了回答的完整性;没有图像时,来自评论和ios 标签栏将文本放在中间
[tab.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -10)]
于 2012-11-29T03:27:00.740 回答
43
你可能想在全球范围内应用这个偏移量,所以我建议
对象-C
[UITabBarItem appearance].titlePositionAdjustment = UIOffsetMake(0, -4);
迅速:
UITabBarItem.appearance().titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -4)
于 2015-03-19T11:18:24.940 回答
10
您可以直接从 Interface Builder(标题位置的自定义偏移量)中执行此操作,如下所示:
于 2016-11-22T19:49:33.927 回答
5
对于 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)
}
于 2020-04-02T09:58:06.727 回答
0
我在这里找到了答案:ios tabbar put text in the middle when no image will try this one and see how it goes :)
更新:它有效。只有 1 行代码。
于 2012-11-29T03:28:52.640 回答