Skip to content

Instantly share code, notes, and snippets.

@krummler
Created April 17, 2020 11:52
Show Gist options
  • Save krummler/f8675bbc6c0673d12e779b39bd0b465a to your computer and use it in GitHub Desktop.
Save krummler/f8675bbc6c0673d12e779b39bd0b465a to your computer and use it in GitHub Desktop.
extension UIButton {
func apply(style: ButtonStyle) {
backgroundColor = nil
titleLabel?.font = style.font
contentEdgeInsets = style.insets
setTitleColor(style.enabled.foreground, for: .normal)
setTitleColor(style.highlighted.foreground, for: .highlighted)
setTitleColor(style.disabled.foreground, for: .disabled)
setBackgroundImage(style.enabled.background, for: .normal)
setBackgroundImage(style.highlighted.background, for: .highlighted)
setBackgroundImage(style.disabled.background, for: .disabled)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment