Skip to content

Instantly share code, notes, and snippets.

@soggybag
Created February 9, 2016 21:45
Show Gist options
  • Save soggybag/8c5aed3d0a1f0079a5d4 to your computer and use it in GitHub Desktop.
Save soggybag/8c5aed3d0a1f0079a5d4 to your computer and use it in GitHub Desktop.
Custom Designable, Inspectable button with border and corner radius.
import UIKit
@IBDesignable
class CustomButton: UIButton {
@IBInspectable var borderColor: UIColor? = UIColor.clearColor() {
didSet {
layer.borderColor = self.borderColor?.CGColor
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = self.borderWidth
}
}
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = self.cornerRadius
layer.masksToBounds = self.cornerRadius > 0
}
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
}
override func drawRect(rect: CGRect) {
self.layer.cornerRadius = self.cornerRadius
self.layer.borderWidth = self.borderWidth
self.layer.borderColor = self.borderColor?.CGColor
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment