Skip to content

Instantly share code, notes, and snippets.

@jasmo2
Forked from soggybag/CustomButton.swift
Created March 14, 2016 03:54
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 jasmo2/8fbbe4cb020c1bcebefd to your computer and use it in GitHub Desktop.
Save jasmo2/8fbbe4cb020c1bcebefd 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