xcode IOS 5 TabBar 自定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7773223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IOS 5 TabBar customization
提问by awDemo
I'm taking advantage of IOS 5's UI customization features to create a custom tabBar. I know how to place a custom background and selection item like so:
我正在利用 IOS 5 的 UI 自定义功能来创建自定义 tabBar。我知道如何像这样放置自定义背景和选择项:
-(void)customizeAppearance {
UIImage *tabBg = [UIImage imageNamed:@"myTabBar.png"];
[[UITabBar appearance] setBackgroundImage:navBg];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"mySelector.png"]];
}
I'd also like to set the "selected" and "unselected" images for the tabBar icons. From the documentation, I see that you use the
我还想为 tabBar 图标设置“已选择”和“未选择”图像。从文档中,我看到您使用
setFinishedSelectedImage: withFinishedUnselectedImage:
method to accomplish this. I have 4 tabs and have created the necessary 8 icons for them. The question is how do I assign each selected/unselected image set to each tab?
方法来实现这一点。我有 4 个标签,并为它们创建了必要的 8 个图标。问题是如何将每个选定/未选定的图像集分配给每个选项卡?
回答by cpprulez
You could call the method for each UITabBarItem in the tabBar property. For example:
您可以在 tabBar 属性中为每个 UITabBarItem 调用该方法。例如:
UIImage *selectedImage = [UIImage imageNamed:@"selected.png"];
UIImage *unselectedImage = [UIImage imageNamed:@"unselected.png"];
UITabBar *tabBar = tabBarViewController.tabBar;
UITabBarItem *item1 = [tabBar.items objectAtIndex:0];
[item1 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
and the same for the other three items. I hope this helps!
其他三项也一样。我希望这有帮助!