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

发布于 2024-12-23 15:52:16 字数 453 浏览 1 评论 0原文

我做了一个标签栏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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

幽梦紫曦~ 2024-12-30 15:52:16

一个可能的解决方案是将带有背景图像的 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];

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

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.

酷到爆炸 2024-12-30 15:52:16

我在此处回答了类似的问题。希望它会有所帮助。

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

时常饿 2024-12-30 15:52:16

查看 NGTabBarController,这是一个具有可自定义背景图像的开源选项卡栏替代品。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文