Skip to content

Instantly share code, notes, and snippets.

@programmarchy
Created April 27, 2017 22:59
Show Gist options
  • Save programmarchy/9a6144d96ea8cfa8e11183b4a87a2dfb to your computer and use it in GitHub Desktop.
Save programmarchy/9a6144d96ea8cfa8e11183b4a87a2dfb to your computer and use it in GitHub Desktop.
View templated images in Interface Builder
import UIKit
@IBDesignable
class TemplateImageButton: UIButton {
#if TARGET_INTERFACE_BUILDER
let templateImageView = UIImageView()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(templateImageView)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
addSubview(templateImageView)
}
override func layoutSubviews() {
templateImageView.frame = bounds
templateImageView.image = currentImage?.withRenderingMode(.alwaysTemplate)
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment