如何禁用 Xcode 中的按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/555846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:58:31  来源:igfitidea点击:

How can I disable a button in Xcode?

iphonexcodecocoa-touchinterface-builder

提问by ashish

I am new to iPhone development. I am building an app by using Xcode but now would like to disable a button. How is this possible?

我是 iPhone 开发的新手。我正在使用 Xcode 构建一个应用程序,但现在想禁用一个按钮。这怎么可能?

回答by Alex Wayne

myButton.enabled = NO;

回答by Andrew Grant

Via code:

通过代码:

myButton.enabled = NO;

If you're using interface builder there's an "enabled" option.

如果您使用的是界面构建器,则有一个“启用”选项。

回答by dannrob

If you are looking for a Swift 3.0 solution:

如果您正在寻找 Swift 3.0 解决方案:

button.isEnabled = false

回答by Kasaname

button.enabled = NO;

button.enabled = NO;

you can set the button property to no and if interface builder you can uncheck the property

您可以将按钮属性设置为 no,如果界面生成器您可以取消选中该属性

回答by W.Baird

 button.enabled = true; 

this will ENABLE the button

这将启用按钮

button.enabled = false;

this will DISABLE the button. If you want to hide the button you can do this

这将禁用按钮。如果你想隐藏按钮,你可以这样做

button.alpha = 0.0;

and if you want to show the button once more you can do this.

如果你想再次显示按钮,你可以这样做。

button.alpha = 1.0

Hope this helps! :)

希望这可以帮助!:)