移动UITabBarItem图像? [英] Moving UITabBarItem Image down?

查看:72
本文介绍了移动UITabBarItem图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常在 UITabBar 的每个标签上,您都有一个小图片和一个命名标签的标题。图像位于标签顶部/居中,以容纳下方的标题。我的问题是:如果你想让tabBar只有一个图像,没有标题可以将图像向下移动,以便在标签内更好地居中?

Normally on each tab of a UITabBar you have a small image and a title naming the tab. The image is positioned/centred towards the top of the tab to accommodate the title underneath. My question is: if you want to have a tabBar with just an image and no title is there a way to move the image down so it centers better within the tab?

我目前正在使用(见下文):

I am using (see below) currently:

[tabBarItem setFinishedSelectedImage:tabSelected withFinishedUnselectedImage:tabUnselected];

但是我更喜欢使用没有标题的更大图像,如果我把图像放大的话大约70pixels @ 2x它开始偏离 UITabBar 的顶部,同时在底部留下大量未使用的空间。

but would prefer to use to larger image with no title, at the moment if I make the image bigger than about 70pixels@2x it starts edging off the top of the UITabBar whilst leaving a lot of unused space at the bottom.

推荐答案

尝试调整 tabBarItem imageInsets (用于移动图标图像)并将控制器标题设置为nil(因此不显示标题)。把这样的东西放到视图控制器中的 -init -viewDidLoad 方法中:

Try adjusting tabBarItem's imageInsets (for moving the icon image) and setting the controllers title to nil (so no title is displayed). Put something like this to -init or -viewDidLoad method in view controller:

Objective-C

self.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
self.title = nil;

Swift

self.tabBarItem.imageInsets = UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0)
self.title = nil

UITabBarItem UIBarItem的子类其中包含 UIEdgeInsets imageInsets 属性。使用插图播放一点,直到它看起来很好(取决于您的tabbar图标图像)

UITabBarItem is a subclass of UIBarItem which has UIEdgeInsets imageInsets property. Play a little with the insets until it looks good (depending on your tabbar icon images)

这篇关于移动UITabBarItem图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆