【问题标题】:How to hide a button in Xcode 6?如何在 Xcode 6 中隐藏按钮?
【发布时间】:2015-01-16 10:15:26
【问题描述】:

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

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

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

提前致谢!

【问题讨论】:

  • 设置button2.alpha = 0,它将是不可见的。您甚至可以在 Interface Builder 中设置它,使其一开始是隐藏的。设置button2.alpha = 1 使其可见。
  • 或者设置button2.hidden = true 会不可见。您可以将其设置为在 Interface Builder 中隐藏,以便它开始隐藏。设置button2.hidden = false 使其可见。

标签: ios xcode swift button


【解决方案1】:

在 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
    }

}

也许这对你有帮助。

【讨论】:

猜你喜欢
  • 2012-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多