title: How to set button image condition in Swift 3
body: <p>I have these <strong>3 (three) UIButton</strong> with <strong>two images (active.png and notactive.png)</strong></p>
  
  <pre><code>Official
  Personal 1
  Personal 2
  </code></pre>
  
  <p>My goal is when I select one of the button, the image is set to active.png while the other two button is set into notactive.png</p>
  
  <p>And the selected button is <strong>store in UILabel output</strong></p>
  
  <p>Appreciate if someone can help.</p>
  
  <p><strong>button.swift</strong></p>
  
  <p>import UIKit</p>
  
  <p>class ViewController: UIViewController {</p>
  
  <pre><code>// MARK: Outlets
  
  @IBOutlet var officialButton: UIButton!
  @IBOutlet var personal1button: UIButton!
  @IBOutlet var personal2button: UIButton!
  @IBOutlet var outputLbl: UITextField!
  
  // MARK: Properties
  
  var output: String!
  var buttons: [UIButton] {
      return [officialButton, personal1button, personal2button]
  }
  
  // MARK: Lifecycle
  
  override func viewDidLoad() {
  
      super.viewDidLoad()
  
      buttons.forEach {
          $0.addTarget(self, action: #selector(didTouchUpInside(button:)), for: .touchUpInside)
          $0.setImage(UIImage(named: "notactive"), for: .normal)
          $0.setImage(UIImage(named: "active"), for: .selected)
      }
  }
  
  // MARK: Methods
  
  func didTouchUpInside(button: UIButton) {
  
      buttons.forEach { $0.isSelected = false }
      button.isSelected = !button.isSelected
  
      outputLbl.text = nil
  
      if button.isSelected {
          outputLbl.text = button.currentTitle
      }
      else if officialButton.isSelected {
          outputLbl.text = "Official"
      }
      else if personal1Button.isSelected {
          outputLbl.text = "P1"
      }
      else if personal2Button.isSelected {
          outputLbl.text = "P2"
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks.</p>