Skip to content

Instantly share code, notes, and snippets.

@zs40x
Created June 7, 2017 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zs40x/4f2e7168bf3c17166f1533ee1a37be62 to your computer and use it in GitHub Desktop.
Save zs40x/4f2e7168bf3c17166f1533ee1a37be62 to your computer and use it in GitHub Desktop.
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