Custom tab bar background image - in iOS 4.x

一世执手 提交于 2019-11-28 03:51:41

问题


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. The project is developed for iOS 4.x, so the iOS5's [tabBar setTabBarBackgroundImage:[UIImage imageNamed:@"custom.jpg"]] does not work. 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];

回答1:


A possible solution would be to put an UIView with your background image exactly behind the UITabBar. Then lower the opacity of your tabbar to 0.5 so you can see the background-image coming through.

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.




回答2:


I have answered similar kind of question here. Hope it will help.




回答3:


Check out NGTabBarController, an open source tab bar replacement with customizable background image.



来源:https://stackoverflow.com/questions/8709802/custom-tab-bar-background-image-in-ios-4-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!