With subclass (will survive layout changes):
override func layoutSubviews() {
super.layoutSubviews()
if let imageView = imageView {
imageView.alpha = 0.2
}
}
Without subclass (transient, suitable to animations):
if let imageView = imageButton.imageView {
imageView.alpha = CGFloat(sender.value)
}
Subclass Source Code
@IBDesignable class FadeButton: UIButton {
@IBInspectable var imageAlpha: CGFloat = 1 {
didSet {
if let imageView = imageView {
imageView.alpha = imageAlpha
}
}
}
override func layoutSubviews() {
super.layoutSubviews()
if let imageView = imageView {
imageView.alpha = imageAlpha
}
}
}
Invoke with imageButton.imageAlpha = alpha
Demo

► Find this solution on GitHub and additional details on Swift Recipes.