xcode 自定义标签栏顶部 1 像素间距

xcode custom tab bar 1 pixel gap at top

我目前正在更新 Xcode 6.

中的一些旧 Xcode 应用程序

我有一个自定义标签栏,用于加载和看起来不错,但在 Xcode 6 中,它在标签栏顶部形成了一个 1px 的间隙,我无法摆脱它,而且看起来真的很糟糕!

我已经阅读了其他一些类似的 SO 帖子并遵循了所有建议,但是其中 none 似乎没有任何效果,并且 1px 的差距仍然存在。

这是我的自定义标签条码:

CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGRect tabbarTopFrame = CGRectMake(0,(screenSize.height - 59),320,10);
UIImageView *tabbarTop = [[UIImageView alloc] initWithFrame:tabbarTopFrame];
tabbarTop.image = [UIImage imageNamed:@"tabbar_top.png"];
[self.tabBarController.view addSubview:tabbarTop];

UIImage *selectedImage0 = [UIImage imageNamed:@"tabbar_introduction_active.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"tabbar_introduction_default.png"];
UIImage *selectedImage1 = [UIImage imageNamed:@"tabbar_nests_active.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"tabbar_nests_default.png"];
UIImage *selectedImage2 = [UIImage imageNamed:@"tabbar_home_active.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"tabbar_home_default.png"];
UIImage *selectedImage3 = [UIImage imageNamed:@"tabbar_dogowners_active.png"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"tabbar_dogowners_default.png"];
UIImage *selectedImage4 = [UIImage imageNamed:@"tabbar_spotted_active.png"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"tabbar_spotted_default.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];

[self.tabBarController.tabBar setClipsToBounds:YES];
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];

item0.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item3.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item4.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

[item0 setImage:[unselectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item1 setImage:[unselectedImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item2 setImage:[unselectedImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item3 setImage:[unselectedImage3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item4 setImage:[unselectedImage4 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

[item0 setSelectedImage:[selectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item1 setSelectedImage:[selectedImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item2 setSelectedImage:[selectedImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item3 setSelectedImage:[selectedImage3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item4 setSelectedImage:[selectedImage4 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

这些图像都是在以前的应用程序代码中使用的,那是在 Xcode 4 中编写的,当时一切正常,所以它一定是在 Xcode 5 或 6 中发生了变化, 或者 iOS7/iOS8?

虽然不是同一个问题,但 SO post (update tab bar height in iOS 7/8 from iOS 6 - UITabBar) 中的某些内容对我有所帮助。

事实证明我根本没有对我的任何代码进行任何更改 - 但只需将图形的高度从 49px 更改为 50px 就解决了问题。

奇数。