Is there a way to change the text position in UITa

2019-03-09 22:02发布

enter image description here

This is a custom tab bar I intended to put up on the screen. However, my partner want the text to be slightly up. How can I do so?

5条回答
再贱就再见
2楼-- · 2019-03-09 22:43

You probably want to apply this offset globally, so I'd suggest

Obj-C

[UITabBarItem appearance].titlePositionAdjustment = UIOffsetMake(0, -4);

Swift:

UITabBarItem.appearance().titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -4)
查看更多
\"骚年 ilove
3楼-- · 2019-03-09 22:43

I've found the answer here: ios tabbar put text in the middle when no image will try this one and see how it goes :)

Update: It works. Only 1 line of code.

查看更多
Root(大扎)
4楼-- · 2019-03-09 22:49

Why don't you just have an empty title property for your view controller and add the title to your custom images for the tab?

UPDATE: For the sake of completeness of answer; from comments and ios tabbar put text in the middle when no image

[tab.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -10)]

查看更多
Explosion°爆炸
5楼-- · 2019-03-09 22:54

You can do it directly from Interface Builder (Custom Offset in Title Position), like this: link

查看更多
啃猪蹄的小仙女
6楼-- · 2019-03-09 23:01

Here's the same trick with Interface builder:

enter image description here

查看更多
登录 后发表回答