简体   繁体   English

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

[英]Custom tab bar background image - in iOS 4.x

I have made a tab bar iOS project, when I received the request to change the tab bar's background image to a custom image. 当我收到将标签栏的背景图像更改为自定义图像的请求时,我已经制作了一个标签栏iOS项目。 The project is developed for iOS 4.x, so the iOS5's [tabBar setTabBarBackgroundImage:[UIImage imageNamed:@"custom.jpg"]] does not work. 该项目是为iOS 4.x开发的,因此iOS5的[tabBar setTabBarBackgroundImage:[UIImage imageNamed:@"custom.jpg"]]不起作用。 Can you suggest me some simple solutions (if there is any possibility, I would not like to change the entire project)? 你能给我一些简单的解决方案(如果有可能,我不想改变整个项目)?

Edit: Only three lines of code can resolve all: 编辑:只有三行代码可以解决所有问题:

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

A possible solution would be to put an UIView with your background image exactly behind the UITabBar . 一个可能的解决方案是将UIView与您的背景图像正好放在UITabBar后面。 Then lower the opacity of your tabbar to 0.5 so you can see the background-image coming through. 然后将标签栏的不透明度降低到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];

Sorry if my code contains some errors. 很抱歉,如果我的代码中包含一些错 I tried doing this by heart... But you'll catch the drift. 我试着用心做这件事......但是你会抓住漂移。

查看NGTabBarController ,一个带有可自定义背景图像的开源标签栏替换。

I have answered similar kind of question here . 在这里回答了类似的问题。 Hope it will help. 希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM