Skip to content

Instantly share code, notes, and snippets.

@Aman2306
Created May 6, 2020 19:17
Show Gist options
  • Save Aman2306/9da91405fd8594741caaf6a660282afd to your computer and use it in GitHub Desktop.
Save Aman2306/9da91405fd8594741caaf6a660282afd to your computer and use it in GitHub Desktop.
A Custom UIButton
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