在故事板和Swift 2中禁用UIButton高亮显示

时间:2022-06-11 14:44:41

I am trying to disable Highlighting on a UIButton setup in Storyboard. I am using Swift on Xcode 7.1. I have the button set to Custom, and I have tried everything I can think of, and it is still highlighting. Here is another question for Objective-C, and I have tried everything on it, even the Storyboard image name white space idea.

我试图在Storyboard中的UIButton设置中禁用突出显示。我正在使用Swift代码7.1。我将按钮设置为Custom,我已经尝试了我能想到的一切,它仍然在突出显示。这是Objective-C的另一个问题,我已经试过了它的所有东西,甚至是故事板的图像名称,空格的概念。

The button is hooked up correctly.

这个按钮连接正确。

How do you disable highlighting? Is it a bug in Xcode?

如何禁用突出显示?它是Xcode中的一个bug吗?

1 个解决方案

#1


2  

I guess you mean you don't want the button to appear to change when it's tapped. One way to do it is by creating a subclass of UIButton that refuses to become highlighted:

我猜你的意思是,你不希望按钮在被点击时出现变化。一种方法是创建一个UIButton的子类,它拒绝高亮显示:

class NonHighlightingButton: UIButton {
    override var highlighted: Bool {
        set { }
        get { return super.highlighted }
    }
}

Then, in your storyboard, set the custom class of your button to NonHighlightingButton:

然后,在故事板中,将按钮的自定义类设置为NonHighlightingButton:

在故事板和Swift 2中禁用UIButton高亮显示

#1


2  

I guess you mean you don't want the button to appear to change when it's tapped. One way to do it is by creating a subclass of UIButton that refuses to become highlighted:

我猜你的意思是,你不希望按钮在被点击时出现变化。一种方法是创建一个UIButton的子类,它拒绝高亮显示:

class NonHighlightingButton: UIButton {
    override var highlighted: Bool {
        set { }
        get { return super.highlighted }
    }
}

Then, in your storyboard, set the custom class of your button to NonHighlightingButton:

然后,在故事板中,将按钮的自定义类设置为NonHighlightingButton:

在故事板和Swift 2中禁用UIButton高亮显示