Last active
May 18, 2019 03:13
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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