Ios5 在iOS 5中自定义选项卡栏时出现错误的图像Y。

Ios5 在iOS 5中自定义选项卡栏时出现错误的图像Y。,ios5,uitabbarcontroller,tabbar,Ios5,Uitabbarcontroller,Tabbar,iOS包括设置FinishedSelectedImage:和FinishedSelectedImage:以自定义选项卡栏。 我创建了一些49高度的纹理,我看到底部有一个奇怪的黑色边框。然后,在添加alpha通道后,我意识到问题是图像向上移动了大约4个点。我给你发了一张截图。 此外,这一条也有同样的问题(黑色奇怪的线),尽管很难看到它。 代码如下: UIImage*selectedImage0=[UIImage ImageName:@“计数按钮按下”]; UIImage*取消选中的eImage

iOS包括设置FinishedSelectedImage:和FinishedSelectedImage:以自定义选项卡栏。 我创建了一些49高度的纹理,我看到底部有一个奇怪的黑色边框。然后,在添加alpha通道后,我意识到问题是图像向上移动了大约4个点。我给你发了一张截图。 此外,这一条也有同样的问题(黑色奇怪的线),尽管很难看到它。

代码如下: UIImage*selectedImage0=[UIImage ImageName:@“计数按钮按下”]; UIImage*取消选中的eImage 0=[UIImage ImageName:@“计数按钮已释放”]

你知道会发生什么吗?
提前感谢。

tabbaritem完成的图像不会垂直居中于选项卡栏上,因为它们是标准选项卡栏项目图标的替代品

选项卡栏项目图像移到顶部,从而为选项卡栏项目标题文本留出空间


tabbaritem完成的图像应仅包含图标。要更改选项卡栏中的选定项目背景,请使用UITabBar中的selectionIndicatorImage属性。您可以创建透明图像,并将UITabBar配置为将其用作选择图像。 在我看来,它清晰而优雅:)


我找到了另一个解决办法。使用Photoshop,我将画布高度从49更改为60,并将透明颜色从0填充到11。而且效果很好:)
UIImage *selectedImage1 = [UIImage imageNamed:@"date_button_pressed"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"date_button_released"];

UIImage *selectedImage2 = [UIImage imageNamed:@"stats_button_pressed"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"stats_button_released"];

UITabBar *tabBar = self.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];

[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
// Create Transparent image on the fly
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);

CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Set tabbar selection image to be the transparent image we've created before
tabBar.selectionIndicatorImage = img;