【问题标题】:How to set custom title attributes for UITabBarItem如何为 UITabBarItem 设置自定义标题属性
【发布时间】:2013-09-16 15:41:33
【问题描述】:

如何为每个 UITabBarItem 设置自定义字体。我发现的只是 [[UITabBarItem 外观] setTitleTextAttributes:...] 但它为所有选项卡设置了相同的属性。 我想为每个 UITabBarItem 设置属性,它必须是自定义的。 像 [tabBarItem setTitleTextAttributes:forState:] 这样的方法不起作用。

【问题讨论】:

  • [self.tabBarItem setTitleTextAttributes:forState:] 成功为我更改了文本样式。您是说希望每个标签的文本样式不同吗?
  • 是的。但是你的方法对我不起作用。我不知道为什么。

标签: iphone ios ios5 uitabbaritem


【解决方案1】:

如果您想完成此操作,请使用图像,但这是不可能的 分别读取每个 UITabBarItem 然后为每个使用图像

UITabBarController *tabBarController=(UITabBarController*)self.window.rootViewController;

UITabBar *tabBar=tabBarController.tabBar;

UITabBarItem *tabBarItemClassic=[tabBar.items objectAtIndex:0];

UITabBarItem *tabBarItemAdvance=[tabBar.items objectAtIndex:1];

UITabBarItem *tabBarItemMore=[tabBar.items objectAtIndex:2];

现在假设我想为 tabBarItemMore 使用不同的颜色。

您可以将标题设置为 nil,并且可以使用自定义设计的图像显示在那里。

在以下情况下,我没有使用标题,而是使用了在图标下方写有标题的图像。

[tabBarItemMore setImage:[[UIImage imageNamed:@"more.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

    [tabBarItemMore  setSelectedImage:[[UIImage imageNamed:@"more.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多