title: Swift, ios 10 UIButton Border
body: <p>I was developing in Swift 3 and I had a little problem with a UIButton. I will try to explain my problem. First I created my UIButton:</p>
  
  <pre><code>let Button: UIButton = {
      let button = UIButton(type: .system)
      button.setBackgroundImage(UIImage(named: "button"), for: .normal)        
      button.layer.borderWidth = 2
      button.layer.borderColor = UIColor(red: 0, green: 0, blue: 80/255, alpha: 1).cgColor
      button.layer.cornerRadius = 10
      //button.translatesAutoresizingMaskIntoConstraints = false
      return button
  }()
  </code></pre>
  
  <p>After in the viewDidLoad I implemented the action:</p>
  
  <pre><code>  button.addTarget(self, action: #selector(buttonUnpressed), for: .touchUpInside)
  </code></pre>
  
  <p>In which "favButtonPressed" is a function with no importance
  The problem is when I touch the button the border doesn't get unhighlighted as the image or the text does. It is a detail of little importance but quite annoying.</p>
  
  <p>I have tried changing the alpha value when pressed and re-change it but the problem is i dont know how to animate it to make the animation for 2 seconds (the next line of code doesnt work, it does change the color but not during 2 seconds):</p>
  
  <pre><code>func buttonUnpressed(){
      UIButton.animate(withDuration: 2, animations: {
          self.button.layer.borderColor = UIColor(red: 0, green: 0, blue: 80/255, alpha: 1).cgColor
      })
  }
  </code></pre>
  
  <p>The question; is there any way of adding the border to the UIButton "total behavior" of highlighting and unhighlighting when pressed?</p>
  
  <p>Excuse me for my english if there are some expression or gramatical faults.</p>
  
  <p>EDIT
  I tried with this function:</p>
  
  <pre><code> func buttonUnpressed(){
      button.alpha = 0.2
      UIButton.animate(withDuration: 1) {
          self.button.alpha = 1
      }
      button.layer.borderColor = UIColor(red: 0, green: 0, blue: 80/255, alpha: 1).cgColor
  }
  </code></pre>
  
  <p>there is a weird highlight of the image but now it works more or less.</p>