iOS5 上使用 API 自定义 TabBar
我尝试了 iOS 5 的新自定义 API,但遇到了一些我不明白的问题。我这样做的方式:
UITabBar *tabBar = [rootController tabBar];
if ([tabBar respondsToSelector:@selector(setBackgroundImage:)])
{
[tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar_bg.png"]];
tabBar.selectionIndicatorImage = [UIImage imageNamed:@"over.png"];
tabBar.tintColor = [UIColor colorWithRed:56.0/255.0 green:63.0/255.0 blue:74.0/255.0 alpha:1.0];
tabBar.selectedImageTintColor = [UIColor colorWithRed:94.0/255.0 green:102.0/255.0 blue:114.0/255.0 alpha:1.0];
}
问题如下图所示:
边框是我的问题.. .并且只有当我尝试使用漂亮的(:P)颜色时才会发生这种情况。如果我尝试使用白色,它看起来像这样:
执行你有什么想法如何解决它吗?
I tried the new Customizing API for iOS 5 and have some problems I don`t understand. The way I do it:
UITabBar *tabBar = [rootController tabBar];
if ([tabBar respondsToSelector:@selector(setBackgroundImage:)])
{
[tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar_bg.png"]];
tabBar.selectionIndicatorImage = [UIImage imageNamed:@"over.png"];
tabBar.tintColor = [UIColor colorWithRed:56.0/255.0 green:63.0/255.0 blue:74.0/255.0 alpha:1.0];
tabBar.selectedImageTintColor = [UIColor colorWithRed:94.0/255.0 green:102.0/255.0 blue:114.0/255.0 alpha:1.0];
}
The problem is shown on the image below:
The border ist my Problem... and it only occurs if I try to use it with nice ( :P ) colors.. if I try it with white it looks like this:
Do you have any ideas how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您创建 UITabBarItem 的子类并实现这些方法,
您可以从这些图像中返回您想要的任何图像,并且它们不会应用任何样式效果。
从技术上讲,这些是私有方法,但您不是调用它们,而是覆盖它们,而且我已经看到很多应用程序使用此技术而没有被拒绝。
您还可以使用类别来覆盖应用程序中所有选项卡项的这些方法。一个好技巧是覆盖 selectedImage 以返回图像,如下所示:
这样,所有选项卡栏项目都将使用您提供的任何图像,而不对 selectedImage 应用任何效果,但仍将使用 unselectedImage 的默认灰色样式。请注意,这意味着您为选项卡栏项目提供带有颜色的图像,而不仅仅是正常的遮罩图像。
If you create a subclass of UITabBarItem and implement the methods
You can return whatever images you want from these and they won't have any styling effects applied.
Technically these are private methods, but you aren't calling them, you are overriding them, and I've seen plenty of apps use this technique without being rejected.
You can also use a category to override these methods for all tabbaritems in your app. A good trick is to just override selectedImage to return image, like this:
That way, all of your tab bar items will use whatever image you supply without applying any effects for the selectedImage, but will still use the default grey styling for the unselectedImage. Note that this means that you supply an image with colours for the tab bar items, not just a mask image as normal.