将 UITabBarItem Image 向下移动? [英] Moving UITabBarItem Image down?
问题描述
通常在 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:
目标 C
self.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
self.title = nil;
迅捷
self.tabBarItem.imageInsets = UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0)
self.title = nil
UITabBarItem
是 UIBarItem
的子类,它具有 UIEdgeInsets imageInsets
属性.稍微使用插图直到它看起来不错(取决于您的标签栏图标图像)
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 Image 向下移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!