【问题标题】:Dissable the tab bar button but want the enabeled image of disssabled tab bar button禁用标签栏按钮,但想要禁用标签栏按钮的标记图像
【发布时间】:2013-06-26 10:59:45
【问题描述】:

我正在制作一个标签栏应用程序。我想禁用一个我可以通过代码制作的标签栏按钮

[[[[[self tabBarController] viewControllers] objectAtIndex:2] tabBarItem] setEnabled:FALSE];

但图像被禁用。我希望启用图像。不通过代码使用自定义图像怎么可能。我不想使用标签栏按钮的自定义图像。我想使用默认选中和未选中的标签栏按钮图像。请提出建议。

提前致谢。

【问题讨论】:

  • 也许您可以设置布尔值以了解启用了哪个选项卡。在委托tabBar:didSelectItem: 中测试这些布尔值。如果与所选选项卡对应的布尔值表示该选项卡未启用,则只需执行return; 即可退出委托。
  • @zbMax - 但是图像变为未选择的图像..即使未启用选项卡按钮,我也想要选择的图像...

标签: iphone ios ipad ios5 ios6


【解决方案1】:

您可以尝试以下操作:将UIBarButtonItem 切换为禁用,而不是切换属性,将tintColor 属性更改为透明颜色。这将防止按钮在点击时被着色。然后,在委托中,检查按钮是否被禁用,如果是则返回:

// inside view controller .m

-(void)disableButton
{
    [barBtn setTintColor:[UIColor clearColor]];
}

-(void)enableButton
{
    [barBtn setTintColor:[UIColor grayColor]];  // whatever color the tint should be
}

-(void)buttonTapped:(id)sender
{
    if ([barBtn tintColor] == [UIColor clearColor])
    {
        return;   // button is disabled, so don't to action
    }
}

【讨论】:

  • 我需要为此创建一个类别??
  • @NiKKi 没有;大概在你的视图控制器的某个地方,你有一些东西会导致按钮被启用/禁用。这调用了 enableButton / disableButton 函数。 buttonTapped:是被点击的实际标签栏按钮的回调。 barBtnUIBarButtonItem,它是实际的标签栏按钮。我稍微修改了代码以使其更清晰
猜你喜欢
  • 2018-01-14
  • 1970-01-01
  • 1970-01-01
  • 2020-06-24
  • 1970-01-01
  • 1970-01-01
  • 2011-10-30
  • 1970-01-01
  • 2011-12-26
相关资源
最近更新 更多