Skip to content

Instantly share code, notes, and snippets.

@andeeliao
Created September 19, 2019 22:18
Show Gist options
  • Save andeeliao/b7ea50e440c5ccf0fef832c00b6be875 to your computer and use it in GitHub Desktop.
Save andeeliao/b7ea50e440c5ccf0fef832c00b6be875 to your computer and use it in GitHub Desktop.
adding any uiview as a uibutton state
extension UIView {
var image: UIImage {
let renderer = UIGraphicsImageRenderer(bounds: bounds)
return renderer.image { rendererContext in
layer.render(in: rendererContext.cgContext)
}
}
}
extension UIButton {
func setBackgroundView(_ view: UIView, for state: UIControl.State) {
self.setBackgroundImage(view.image, for: state)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment