skip to Main Content

I have a button that should be activated after the user selects a photo from library or take a photo. But as long as there is no photo the button should not work.

2

Answers


  1. UIButton has a property called isEnabled (refer to Apple Docs).

    To enable the button you can write:

    myButton.isEnabled = true
    

    More detailed explanation:
    First of all you need to disable the button, when the ViewController is loaded. Ideally you do this in the viewWillAppear function:

    override func viewWillAppear(_ animated: Bool) {
      myButton.isEnabled = false
      super.viewWillAppear(animated)
    }
    

    And when the photo is loaded you can enable the button:

    func selectPhoto() {
      // your code to select the photo
      myButton.isEnabled = true
    }
    
    Login or Signup to reply.
  2. Before the user selects a photo from library or take a photo

    button.isEnabled = false
    

    After the user selects a photo from library or take a photo

    button.isEnabled = true
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search