2012-01-03 84 views
6

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

编辑:代码 三线仅是可以解决所有:

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

回答

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

谢谢你,这是一个有益的想法:) – MMMM 2012-01-03 09:55:50

0

我已经回答了类似问题here。希望它会有所帮助。