Is there a way to change the text position in UITa

2019-03-09 22:10发布

问题:

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?

回答1:

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)]



回答2:

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)


回答3:

Here's the same trick with Interface builder:



回答4:

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



回答5:

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.