用Swift3隐藏动态按钮

时间:2017-02-16 16:48:02

标签: swift3 uibutton

我想用Swift 3隐藏一个动态按钮,但我无法完成它。我刚开始使用Swift,但考虑到开发应用程序会有一些时间压力。

按下ButtonGen1后,我想隐藏此按钮并查看其他2个按钮,即ButtonGen2_1和ButtonGen2_2。

使用Google我尝试了几件事。例如以下内容:

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    createButtonGen1()
    buttonGen1?.removeFromSuperview
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func createButtonGen1 ()
{
    let buttonGen1 = UIButton(frame: CGRect(x:100, y: 100, width: 100, height: 50))
    buttonGen1.setTitle("Is the original visit to this outlet to Eat or Drink?", for: .normal)
    buttonGen1.setTitleColor(UIColor.orange, for: .normal)
    buttonGen1.addTarget(self, action: #selector(buttonActionGen1), for: .touchUpInside)
    self.view.addSubview(buttonGen1)
}

func createButtonGen2_1 ()
{
    let buttonGen2_1 = UIButton(frame: CGRect(x:50, y: 100, width: 100, height: 150))
    buttonGen2_1.setTitle("Is the name Restaurant?", for: .normal)
    buttonGen2_1.setTitleColor(UIColor.blue, for: .normal)
    buttonGen2_1.addTarget(self, action: #selector(buttonAction2_1), for: .touchUpInside)
    self.view.addSubview(buttonGen2_1)
}

func createButtonGen2_2 ()
{
    let buttonGen2_2 = UIButton(frame: CGRect(x:150, y: 100, width: 100, height: 150))
    buttonGen2_2.setTitle("Is the name Restaurant?", for: .normal)
    buttonGen2_2.setTitleColor(UIColor.red, for: .normal)
    buttonGen2_2.addTarget(self, action: #selector(buttonAction2_2), for: .touchUpInside)
    self.view.addSubview(buttonGen2_2)
}

func buttonActionGen1(sender: UIButton!) {
// ----> HOW TO HIDE BUTTON buttonGen1 
    buttonGen1.hidden = true
    createButtonGen2_1 ()
    createButtonGen2_2 ()
}

func buttonAction2_1(sender: UIButton!)
{
    print("Button 2_1 tapped")
}

func buttonAction2_2(sender: UIButton!)
{
    print("Button 2_2 tapped")
}

如何隐藏按钮buttonGen1?!?!?!?

非常感谢您的帮助!!!

0 个答案:

没有答案