Skip to content

Instantly share code, notes, and snippets.

@bryanstrader
Forked from soggybag/CustomButton.swift
Last active July 18, 2017 21:51
Show Gist options
  • Save bryanstrader/b6ad344d97a7411531001e230d5acdf0 to your computer and use it in GitHub Desktop.
Save bryanstrader/b6ad344d97a7411531001e230d5acdf0 to your computer and use it in GitHub Desktop.
Custom Designable, Inspectable button with border and corner radius.
import Foundation
import UIKit
@IBDesignable
class CustomButton: UIButton {
@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 draw(_ rect: CGRect) {
self.layer.cornerRadius = self.cornerRadius
self.layer.borderWidth = self.borderWidth
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment