如何隐藏 Xcode 6 中的按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27007631/
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-15 06:12:32  来源:igfitidea点击:

How to hide a button in Xcode 6?

iosxcodeswiftbutton

提问by Schuey999

All I want to do is keep a button hidden until another button is pressed.

我想要做的就是隐藏一个按钮,直到按下另一个按钮。

For example, Button 1 is visible, but Button 2 isn't. When I press Button 1, I need Button 2 to appear.

例如,按钮 1 可见,但按钮 2 不可见。当我按下按钮 1 时,我需要出现按钮 2。

Also, I am programming in Xcode 6 using Swift.

另外,我正在使用 Swift 在 Xcode 6 中进行编程。

Thanks in advance!

提前致谢!

回答by Dharmesh Kheni

The sample code for hiding a button in Swift:

在 Swift 中隐藏按钮的示例代码:

import UIKit

class ViewController: UIViewController {

// Create outlet for both the button
@IBOutlet weak var button1: UIButton!
@IBOutlet weak var button2: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()
    //Set button2 hidden at start
    button2.hidden = true
}



//Here is the action when you press button1 which is visible
@IBAction func button1(sender: AnyObject) {
    //Make button2 Visible
    button2.hidden = false
    }

}

May be this can help you.

也许这可以帮助你。