【发布时间】:2010-10-25 14:45:29
【问题描述】:
我可以在我的视图中显示一个黑色样式的 UIBarButtonItem 而不使用下面的 UIToolBar 吗?
UIToolBar总是有一种边框的东西,我希望系统UIBarButtonItem是黑色的,就像一个黑色的标准取消按钮,而不是UIToolBar
我该怎么做?
谢谢
【问题讨论】:
标签: iphone uibarbuttonitem uitoolbar
我可以在我的视图中显示一个黑色样式的 UIBarButtonItem 而不使用下面的 UIToolBar 吗?
UIToolBar总是有一种边框的东西,我希望系统UIBarButtonItem是黑色的,就像一个黑色的标准取消按钮,而不是UIToolBar
我该怎么做?
谢谢
【问题讨论】:
标签: iphone uibarbuttonitem uitoolbar
有一个厚颜无耻的 hack 可以帮助你解决这个问题。
您想使用样式设置为UISegmentedControlStyleBar 且只有一项的 UISegmentedControl。您还需要将setMomentary 设置为是 - 使其表现得像一个按钮:
UISegmentedControl *myCustomButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Hello",nil]];
[myCustomButton setSegmentedControlStyle:UISegmentedControlStyleBar];
[myCustomButton setTintColor:[UIColor blackColor]];
[myCustomButton setMomentary:YES];
[self.view addSubview:myCustomButton];
这将为您提供一个看起来像 UIBarButtonItem 的按钮,您可以将其添加到普通视图中,就好像它是一个按钮一样。您也可以添加目标和操作。 :)
这就是你得到的:像这样的东西:
【讨论】:
setMomentary 所做的,它会像普通按钮一样暂时显示一个突出显示......尝试将 tintColor 设置为darkGrayColor 看看是否有任何区别。可能blackColor 太暗了,没有更暗的了。 :p
我还没有完全做过类似的事情,但我建议你可以以某种方式将 UIToolBar 的所有子视图的 alpha 设置为零,但 UIBarButtonItem 除外。让 UIBarButtonItem 可见。
UIToolBar 继承自 UIView,所以我的第一个尝试是将其 backgroundColor 设置为 clearColor。
【讨论】: