Skip to content

Instantly share code, notes, and snippets.

@ConorBrady
Last active April 26, 2017 14:05
Show Gist options
  • Save ConorBrady/308b1bd7bfb5caf5e496cac63255f787 to your computer and use it in GitHub Desktop.
Save ConorBrady/308b1bd7bfb5caf5e496cac63255f787 to your computer and use it in GitHub Desktop.
public extension UIButton {
func styleText(font: UIFont, color: UIColor) -> UIButton {
return self <== {
$0.titleLabel?.font = font
$0.setTitleColor(color, for: .normal)
}
}
func styleBase() -> UIButton {
return self <== {
$0.styleRoundCorners()
$0.contentEdgeInsets = UIEdgeInsets(top: 5, left: 20, bottom: 5, right: 20)
}
}
func styleInfo() -> UIButton {
return self <== {
$0.setImage(UIImage(named: "info", bundleFor: BundleRef.self), for: .normal)
}
}
func stylePrimary(fontSize: CGFloat) -> UIButton {
return self <== {
$0.styleBase()
.styleBackground(color: .hubspot, pressedColor: UIColor.hubspot.darkened(amount: 0.05))
.styleText(font: .demiBold(size: fontSize), color: .white)
}
}
func styleSecondary(fontSize: CGFloat) -> UIButton {
return self <== {
$0.styleBase()
.styleBackground(color: UIColor.clear, pressedColor: UIColor.hubspot.withAlphaComponent(0.1))
.styleText(font: .demiBold(size: fontSize), color: .hubspot)
.style(borderColor: UIColor.hubspot)
}
}
func styleBackground(color: UIColor, pressedColor: UIColor) -> UIButton {
return self <== {
$0.setBackgroundImage(UIImage(with: color), for: .normal)
$0.setBackgroundImage(UIImage(with: pressedColor), for: .highlighted)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment