Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import UIKit
@IBDesignable
class BorderedButton: UIButton {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setup()
}
override init(frame: CGRect) {
super.init(frame: frame)
self.setup()
}
override var tintColor: UIColor! {
get {
return super.tintColor
}
set(newValue) {
super.tintColor = newValue
layer.borderColor = tintColor.cgColor
setTitleColor(tintColor, for: .normal)
setTitleColor(tintColor, for: .highlighted)
}
}
private func setup() {
layer.borderWidth = 1.0
layer.borderColor = tintColor.cgColor
layer.cornerRadius = 5.0
clipsToBounds = true
contentEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
imageEdgeInsets = UIEdgeInsets(top: 1, left: 8, bottom: 8, right: 1)
setTitleColor(tintColor, for: .normal)
setTitleColor(tintColor, for: .highlighted)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment