【问题标题】:How to change color of TabBarItem when its set enabled False启用 False 时如何更改 TabBarItem 的颜色
【发布时间】:2015-06-02 11:07:48
【问题描述】:

我禁用了 tabBar 项目,然后 bar 按钮变成灰色。

我想改变它的颜色,但不能这样做。它默认为灰色。

当我 setEnabled 为 true 时,它​​显示原始颜色为白色。

[[[[self.tabBarController tabBar]items]objectAtIndex:0]setEnabled:FALSE];

【问题讨论】:

标签: ios


【解决方案1】:

我在appDelegate 中使用过它,对我来说效果很好。

 [[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor whiteColor]];

 [[UITabBar appearance] setTintColor:[UIColor whiteColor]];

但是当我在viewController 类中设置启用 False 时,它​​会变成灰色。

【讨论】:

  • 我仍然没有解决选项卡栏的那个暗淡按钮。
【解决方案2】:
  // this will generate a red tab bar
    tabBarController.tabBar.barTintColor = [UIColor redColor];

    // this will give selected icons and text your apps tint color
    tabBarController.tabBar.tintColor = [UIColor redColor];

更新:

self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
self.tabBarController.tabBar.translucent = false;
self.tabBarController.tabBar.tintColor = [UIColor blueColor];

【讨论】:

  • 但是当我使用 self.tabBarController.tabBar.tintColor = [UIColor whiteColor]; self.tabBarController.tabBar.barTintColor = [UIColor whiteColor];在 setEnabled False TabBarItem 之后它看起来是灰色的。
  • 我想禁用当前选中的 TabBarItem 以防止用户再次点击同一个项目。为此,我禁用了当前选定的 TabBar 项。 [[[[self.tabBarController tabBar]items]objectAtIndex:currentIndex]setEnabled:FALSE];我的问题是当我禁用该项目时。它变得部分变暗。因此,该项目被选中,其启用属性设置为 FALSE。在这些情况下,调光器(由于 setEnable:FALSE)“获胜”,并且 TabBarItem 图像变暗而不是突出显示。有办法防止变暗效果吗?
  • omg 你不需要禁用它,你需要的只是当用户再次点击按钮时检查用户是否已经加载此视图或设置标志 userhitMidTap=yes 并且不要运行你的代码,如果是的
  • 我无法设置标签和呼叫代表,因为有两个屏幕将有条件地打开,所以我必须禁用第一个标签栏项目
猜你喜欢
  • 2016-05-31
  • 1970-01-01
  • 2023-02-08
  • 1970-01-01
  • 2014-06-26
  • 1970-01-01
  • 2011-09-27
  • 1970-01-01
  • 2012-05-22
相关资源
最近更新 更多