title: How to set the alpha of an UIImage in SWIFT programmatically?
body: <p>I found a lot solutions here but not for <strong>Swift</strong>, and I know you can do this with a UIImageView, but in my case i need an programmatically set alpha transparent background image for an <strong>UIButton</strong>. Best would be an UIImage extension!</p>
  
  <pre><code>let img = UIImage(named: "imageWithoutAlpha")
  var imgInsets = UIEdgeInsetsMake(0, 24, 0, 24)
  image = image!.resizableImageWithCapInsets(imgInsets)
  
  let myButton = UIButton(frame: CGRect(x: 50, y: 50, width: img!.size.width, height: img!.size.height))
  myButton.setBackgroundImage(img, forState: UIControlState.Normal)
  myButton.contentEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 20)
  myButton.setTitle("Startbutton", forState: UIControlState.Normal)
  myButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
  myButton.sizeToFit()
  view.addSubview(myButton)
  </code></pre>
  
  <p>Current result:</p>
  
  <p><img src="https://i.stack.imgur.com/e9AoL.png" alt="current"></p>
  
  <p>Desired result:</p>
  
  <p><img src="https://i.stack.imgur.com/7Xti3.png" alt="desired"></p>