Skip to content

Instantly share code, notes, and snippets.

@adamgraham
Last active May 18, 2019 03:13
Show Gist options
  • Save adamgraham/354019b29d7f3b8c9d3dbb2147dc3cc7 to your computer and use it in GitHub Desktop.
Save adamgraham/354019b29d7f3b8c9d3dbb2147dc3cc7 to your computer and use it in GitHub Desktop.
An @IBDesignable extension of the iOS class UIView to provide customization of shadows within Interface Builder.
protocol DesignableShadow {
var shadowColor: UIColor? { get set }
var shadowOffset: CGSize { get set }
var shadowRadius: CGFloat { get set }
var shadowOpacity: Float { get set }
}
@IBDesignable extension UIView: DesignableShadow {
@IBInspectable var shadowColor: UIColor? {
get {
guard let cgColor = self.layer.shadowColor else { return nil }
return UIColor(cgColor: cgColor)
}
set { self.layer.shadowColor = newValue?.cgColor }
}
@IBInspectable var shadowOffset: CGSize {
get { return self.layer.shadowOffset }
set { self.layer.shadowOffset = newValue }
}
@IBInspectable var shadowRadius: CGFloat {
get { return self.layer.shadowRadius }
set { self.layer.shadowRadius = newValue }
}
@IBInspectable var shadowOpacity: Float {
get { return self.layer.shadowOpacity }
set { self.layer.shadowOpacity = newValue }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment