Skip to content

Instantly share code, notes, and snippets.

@dchakarov
Last active October 2, 2017 01:31
Show Gist options
  • Save dchakarov/81a241ba96babcebf6893023458be879 to your computer and use it in GitHub Desktop.
Save dchakarov/81a241ba96babcebf6893023458be879 to your computer and use it in GitHub Desktop.
Add border width, border colour and radius to UIView as inspectable properties, accessible in Interface Builder
import UIKit
@IBDesignable
extension UIView {
@IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
}
}
@IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
}
}
@IBInspectable var borderColor: UIColor? {
get {
return UIColor(cgColor: layer.borderColor!)
}
set {
layer.borderColor = newValue?.cgColor
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment