单击按钮后,Swift制作标签消失

时间:2016-06-23 17:18:31

标签: swift

我想让标签消失并再次出现,只需点击一下按钮,然后再次点击该按钮重新出现,以减少屏幕上的混乱。

首次运行时的以下代码使按钮消失。我想要它做什么,但是当我把它关闭然后再次运行并按下按钮时,代码突然没有起作用意味着我的标签没有消失。我没有改变任何代码;我所做的就是再次运行它。

我这样做是学校小组项目的一部分。如果有人能帮助我解决我的问题,那就太棒了。谢谢。

P.S。 PrepInfo是我试图隐藏的按钮,PrepButtton是按下的按钮,我想让PrepInfo标签消失。

import UIKit

class BackgroundViewController: UIViewController {
    @IBAction func PrepButton(sender: AnyObject) {
        func hide() {
            PrepInfo.hidden = false
        }

        hide()
    }

    @IBOutlet weak var PrepInfo: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

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

    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
}

1 个答案:

答案 0 :(得分:0)

如果您的标签名为myLabel,请尝试此操作:

// In the code you write to handle button tap

myLabel.hidden = true
相关问题