ios - 自定义标签栏背景图片 - 在 iOS 4.x 中

标签 ios uitabbarcontroller uitabbar

当我收到将标签栏的背景图像更改为自定义图像的请求时,我制作了一个标签栏 iOS 项目。该项目是为 iOS 4.x 开发的,所以 iOS5 的 [tabBar setTabBarBackgroundImage:[UIImage imageNamed:@"custom.jpg"]] 不起作用。你能给我一些简单的解决方案吗(如果有可能,我不想改变整个项目)?

编辑: 只需三行代码即可解决所有问题:

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"customImage.png"]];
[self.tabBarController.tabBar insertSubview:imageView atIndex:0];
[imageView release];

最佳答案

一个可能的解决方案是将带有背景图像的 UIView 正好放在 UITabBar 后面。然后将标签栏的不透明度降低到 0.5,这样您就可以看到背景图像。

UIView *bckgrndView = [[UIView alloc] initWithFrame:CGRectMake(tabbar.frame.coords.x, tabbar.frame.coords.y, tabbar.frame.size.width, tabbar.frame.size.height)];
[bckgrndView setBackgroundImage:[UIImage imageNamed:@"custom.jpg"]];
[tabbar.superView insertSubView:bckgrndView belowSubview:tabbar];
tabbar.alpha = 0.5;
[bckgrndView release];

抱歉,如果我的代码包含一些错误。我试着用心去做……但你会明白的。

关于ios - 自定义标签栏背景图片 - 在 iOS 4.x 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8709802/

相关文章:

iOS:iPad ImageView 中的底部缩略图栏

ios - Libgdx IOS 不工作?

iphone - 如何更改选项卡栏 Controller 应用程序中的选项卡数量?

objective-c - 从 AppDelegate 更改选项卡和推送 View

ios - UITabbarController firSTLy 选定的选项卡表现异常

iphone - 更改标签栏颜色时如何摆脱 UITabBar 上方的黑线

ios - 如何在 Swift 中使用 SCNetworkReachability

iphone - AppDelegate 中的 UITabBarDelegate

swift - 在 swift 中将第二个选项卡设置为默认选项卡

ios - UICollectionView Cell 的阴影在 cell 即将出屏时突然消失