Skip to content

Instantly share code, notes, and snippets.

@shishirthedev
Created January 8, 2019 20:02
Show Gist options
  • Save shishirthedev/ccde47f874cffbb7ba861fd4d8d46eee to your computer and use it in GitHub Desktop.
Save shishirthedev/ccde47f874cffbb7ba861fd4d8d46eee to your computer and use it in GitHub Desktop.
import UIKit
@IBDesignable class CustomButton: UIButton {
@IBInspectable var borderWidth: CGFloat = 0.0 {
didSet {
self.layer.borderWidth = borderWidth
}
}
@IBInspectable var borderColor: UIColor = UIColor.white{
didSet{
self.layer.borderColor = borderColor.cgColor
}
}
@IBInspectable var isRoundedButton : Bool = false{
didSet{
setUpView()
}
}
@IBInspectable var cornerRadius: CGFloat = 0.0 {
didSet {
setUpView()
}
}
override func awakeFromNib() {
super.awakeFromNib()
setUpView()
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
setUpView()
}
override func layoutSubviews(){
super.layoutSubviews()
setUpView()
}
internal func setUpView() {
if isRoundedButton {
self.layer.cornerRadius = self.bounds.height/2;
self.clipsToBounds = true
}else{
self.layer.cornerRadius = self.cornerRadius;
self.clipsToBounds = true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment