简体   繁体   English

标签栏垂直偏移iOS 5

[英]Tab bar vertical offset iOS 5

http://i.stack.imgur.com/NAqSJ.png http://i.stack.imgur.com/NAqSJ.png

Hi 你好

I'm having a vertical offset problem with my custom made tab bar. 我的定制标签栏有垂直偏移问题。 There appears to be a black gap between the UIImages and the bottom of the screen. UIImages与屏幕底部之间似乎存在黑色间隙。 How can this be fixed? 怎么解决这个问题? I'm using the following code in my viewDidLoad() method of the first viewController: 我在第一个viewController的viewDidLoad()方法中使用以下代码:

[super viewDidLoad];
UIImage *selectedImage0 = [UIImage imageNamed:@"tabBarButtonHomeSelected.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"tabBarButtonHomeUnselected.png"];

UIImage *selectedImage1 = [UIImage imageNamed:@"tabBarButtonUserSelected.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"tabBarButtonUserUnselected.png"];

UIImage *selectedImage2 = [UIImage imageNamed:@"tabBarButtonPricetagSelected.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"tabBarButtonPricetagUnselected.png"];

UIImage *selectedImage3 = [UIImage imageNamed:@"tabBarButtonStarSelected.png"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"tabBarButtonStarUnselected.png"];

UIImage *selectedImage4 = [UIImage imageNamed:@"tabBarButtonGearSelected.png"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"tabBarButtonGearUnselected.png"];

UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
UITabBarItem *item4 = [tabBar.items objectAtIndex:4];

[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];

I kindly thank you. 我很感谢你。

Normally the tab titles would go into that space. 通常标签标题会进入该空间。 Your tab items all have empty titles, is that intentional? 你的标签项都有空标题,是故意的吗? If yes, then you should change the default frame of your toolbar view, probably by increasing its frame.origin.y by the amount of the gap. 如果是,那么您应该更改工具栏视图的默认框架,可能是通过增加其frame.origin.y的间隙量。

The solution is to make three types of images. 解决方案是制作三种类型的图像。 First you need a background for your TabBar. 首先,您需要TabBar的背景。 Second you need one image with the size of one button for the selected or highlighted background of one tab. 其次,您需要一个尺寸为一个按钮的图像,用于一个选项卡的选定或突出显示的背景。 Third you need your icons without any background. 第三,你需要没有任何背景的图标。

Now you set your TabBar background with 现在用你的TabBar背景设置

[tabBar setBackgroundImage:[UIImage imageNamed:@"background.png"]];

then you set your highlighted background tile with: 然后设置突出显示的背景图块:

[tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"selected.png"]];

then you need to set your icons like you did in your question. 然后你需要像你在问题中那样设置你的图标。 This should do the job. 这应该做的工作。

You can fix this in Storyboard now. 您现在可以在Storyboard中解决此问题。 故事板大小检查器图像插入调整

Select the Tab Bar Item you want to adjust, open the Size Inspector, and adjust the Top and Bottom Image Insets. 选择要调整的选项卡栏项目,打开“大小”检查器,然后调整“顶部和底部图像插入”。 You need to adjust them the same amount or they will just squish/stretch your image (so +5 in Top, and -5 in Bottom) 你需要调整它们相同的数量,否则它们只会挤压/拉伸你的图像(所以在顶部+5,在底部-5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM