突出显示时更改 UIButton 的背景颜色
问题描述
您好,我想更改用户点击按钮的 UIButton 背景颜色.
Hi I want to change the UIButton background color which user Tap on the button.
我正在使用渐变显示背景颜色,当用户点击时我需要更改渐变颜色.
I am showing background color using gradient, when user tap I need to change the gradient color.
推荐答案
不建议更改 UIButton 的内部层级,因为它可能会在未来的 iOS 更新中中断.此外,它可能会导致 Apple 拒绝您的申请.更好的解决方案是创建一个按钮子类.这是一个如何做的例子:
Changing the internal layer hierarchy of a UIButton is not recommended since it may break in a future update of the iOS. Also, it may cause Apple to reject your application. A better solution would be to create a button subclass. Here is an example of how to do it:
您可能需要对其进行一些修改以使其执行您想要的操作,但我认为您已了解基本概念.
You may need to modify it a bit to get it to do what you want but I think you get the basic idea.
这篇关于突出显示时更改 UIButton 的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!