自定义标签栏背景图像 - 在 iOS 4.x 中
我做了一个标签栏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];
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一个可能的解决方案是将带有背景图像的
UIView
恰好放在UITabBar
后面。然后将标签栏的不透明度降低到 0.5,这样您就可以看到背景图像。抱歉,如果我的代码包含一些错误。我试着用心做这件事......但你会明白的。
A possible solution would be to put an
UIView
with your background image exactly behind theUITabBar
. Then lower the opacity of your tabbar to 0.5 so you can see the background-image coming through.Sorry if my code contains some errors. I tried doing this by heart... But you'll catch the drift.
我在此处回答了类似的问题。希望它会有所帮助。
I have answered similar kind of question here. Hope it will help.
查看 NGTabBarController,这是一个具有可自定义背景图像的开源选项卡栏替代品。
Check out NGTabBarController, an open source tab bar replacement with customizable background image.