UIControlStateHighlighted

UIControlStateHighlighted

本文介绍了按住自定义 UIButton 时更改深灰色突出显示的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义 UIButton,它是一个云、透明的黑白 .png 文件,没有关闭状态,只有一个图像.当用手指轻敲并按住它时,它会变成深灰色.我正在尝试将那种深灰色改为不那么压抑的东西.该按钮在视图中处于打开状态,而不是在选项卡栏、工具栏或导航控制器中.

I have a custom UIButton which is a cloud, transparent black and white .png file, with no down state, just one image. When tapping and holding the finger over it, it turns dark grey. I'm trying to change that dark grey to something a little less oppressive. The button is out in the open in a view, not in a tab bar, tool bar, or navigation controller.

我已经尝试过设置 tintColor(文档告诉我它只适用于某些"类型的按钮,没有说明是哪一种).

I've already tried setting tintColor (which the documentation helpfully informs me is only suitable for 'some' types of buttons, which no indication as to which).

我还尝试更改在 Interface Builder 中可以找到的所有与突出显示颜色、默认状态等相关的内容.没有任何改变.

I've also tried changing everything I can find in Interface Builder relating to highlight colours, default states, etc. Nothing has made a difference at all.

我什至尝试将按钮自己的图像设置为其 UIControlStateHighlighted 状态,但即使这样,当我将手指放在它上面时也会出现深灰色覆盖层.

I've even tried setting the button's own image for its UIControlStateHighlighted state, but even this causes the dark grey overlay to appear when I hold my finger over it.

我怎样才能改变这种颜色?我在 SO 上查看了许多其他问题,但无法找到适合我的解决方案.任何帮助将不胜感激!

How can I change that colour? I've looked at numerous other issues here on SO and have been unable to find a solution that works for me. Any help would be greatly appreciated!

我使用 UIImage 类别解决了问题,该类别添加了一个方法,该方法使用 CoreGraphics 将色调应用于提供的 .然后我将那个图像设置为亮点,一切都很好.似乎很多箍拉来改变苹果应该让我们改变的颜色,但是 c'est la vie.

I Solved the problem using a category of UIImage which adds a method that uses CoreGraphics to apply a tint to a provided UIImage. I then set THAT image as the highlight, and all is well. Seems a lot of hoop-la to change a colour Apple should've let us change, but c'est la vie.

推荐答案

您说您为 UIControlStateHighlighted 状态设置了自定义图像.这应该禁用默认行为.

You said you set a custom image for the UIControlStateHighlighted state. This should disable the default behaviour.

如果您仍然有问题,您可以通过将 adjustsImageWhenHighlighted 属性设置为 NO 来禁用此效果,并使用您想要的任何自定义效果.

If you still have problems you can disable this effect by setting the adjustsImageWhenHighlighted property to NO and use whatever custom effect you want.

这篇关于按住自定义 UIButton 时更改深灰色突出显示的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 07:49