Skip to content

Instantly share code, notes, and snippets.

@rajohns08
Last active November 14, 2017 09:00
Show Gist options
  • Save rajohns08/ead7981593181033d75f to your computer and use it in GitHub Desktop.
Save rajohns08/ead7981593181033d75f to your computer and use it in GitHub Desktop.
iOS / Swift - IBDesignable and IBInspectable working example for a UIButton subclass with a border
import UIKit
@IBDesignable
class BorderButton: UIButton {
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
@IBInspectable var borderColor: UIColor? = UIColor.clearColor() {
didSet {
layer.borderColor = borderColor?.CGColor
}
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment