按住自定义UIButton时更改深灰色突出显示的颜色? [英] Change colour of dark grey highlight when holding down custom UIButton?

查看:496
本文介绍了按住自定义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 将色调应用于提供的 UIImage 。然后我将THAT图像设置为亮点,一切都很好。似乎有很多改变颜色的苹果应该让我们改变颜色,但是我可以改变它。

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 <来禁用此效果/ code>属性为并使用您想要的任何自定义效果。

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时更改深灰色突出显示的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆