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

MMM*_*MMM 6 uitabbarcontroller uitabbar ios

当我收到将标签栏的背景图像更改为自定义图像的请求时,我已经制作了一个标签栏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];
Run Code Online (Sandbox Code Playgroud)

Jul*_*les 3

一个可能的解决方案是将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];
Run Code Online (Sandbox Code Playgroud)

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