自定义iOS 4.x中的选项卡栏背景图像

6
我做了一个选项卡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];
3个回答

3

一个可能的解决方案是将一个带有你的背景图片的 UIView 置于 UITabBar 正后方。然后将你的 tabbar 不透明度降低到 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];

如果我的代码有些错误,对不起。我尽力了...但你会明白的。


0

请查看NGTabBarController,这是一个开源的选项卡栏替代品,具有可自定义的背景图像。


0

我曾经在这里回答过类似的问题。希望能对你有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接