how to hide/show a button in swift

前端 未结 4 1827
攒了一身酷
攒了一身酷 2021-02-12 03:16

I\'m trying to have an if statement that will make a button hidden when a label displays a certain status, and appears when the label says something else. The name of the label

4条回答
  •  青春惊慌失措
    2021-02-12 03:53

    The sample code for hiding a button in 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.isHidden = true
    }
    
    
    
    //Here is the action when you press button1 which is visible
    @IBAction func button1(sender: AnyObject) {
        //Make button2 Visible
        button2.isHidden = false
        }
    
    }
    

    And

    You have to make the UIButton a property of the class if you want to keep a reference to it. Then you can access it using self.takePhotoButton.

提交回复
热议问题