Comment définir l'alpha d'une UIImage dans SWIFT par programmation?

J'ai trouvé beaucoup de solutions ici, mais pas pour Swift, et je sais que vous pouvez le faire avec une UIImageView, mais dans mon cas, j'ai besoin de définir par programmation alpha image de fond transparente pour un UIButton. Le mieux serait une UIImage extension!

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)

Résultat courant:

Comment définir l'alpha d'une UIImage dans SWIFT par programmation?

Résultat souhaité:

Comment définir l'alpha d'une UIImage dans SWIFT par programmation?

InformationsquelleAutor Peter Kreinz | 2015-02-14