【问题标题】:IOS 5 TabBar customizationIOS 5 TabBar 自定义
【发布时间】:2011-10-14 20:28:14
【问题描述】:

我正在利用 IOS 5 的 UI 自定义功能来创建自定义 tabBar。我知道如何像这样放置自定义背景和选择项:

-(void)customizeAppearance {
    UIImage *tabBg = [UIImage imageNamed:@"myTabBar.png"];
    [[UITabBar appearance] setBackgroundImage:navBg];

    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"mySelector.png"]];
}

我还想为 tabBar 图标设置“选中”和“未选中”的图像。从文档中,我看到您使用了

setFinishedSelectedImage: withFinishedUnselectedImage:

实现这一点的方法。我有 4 个选项卡,并为它们创建了必要的 8 个图标。问题是如何将每个选定/未选定的图像集分配给每个选项卡?

【问题讨论】:

  • 这很棒。我没有注意到您可以自定义标签栏。投票! :) 你知道我是否可以让它的一部分透明,所以它不一定有矩形形状?

标签: iphone xcode ios5


【解决方案1】:

您可以在 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];

其他三项也一样。我希望这会有所帮助!

【讨论】:

  • 感谢您回答如此基本的问题!我很感激,是的,这就是我一直在寻找的......
猜你喜欢
  • 1970-01-01
  • 2012-10-28
  • 2013-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-25
相关资源
最近更新 更多