Skip to content

Instantly share code, notes, and snippets.

@vikdenic
Created October 2, 2019 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikdenic/459818a524b1382388dad0398ec33355 to your computer and use it in GitHub Desktop.
Save vikdenic/459818a524b1382388dad0398ec33355 to your computer and use it in GitHub Desktop.
shadow extnesions
@IBDesignable extension UIView {
/* The color of the shadow. Defaults to opaque black. Colors created
* from patterns are currently NOT supported. Animatable. */
@IBInspectable var shadowColor: UIColor? {
set {
layer.shadowColor = newValue!.cgColor
}
get {
if let color = layer.shadowColor {
return UIColor(cgColor:color)
}
else {
return nil
}
}
}
/* The opacity of the shadow. Defaults to 0. Specifying a value outside the
* [0,1] range will give undefined results. Animatable. */
@IBInspectable var shadowOpacity: Float {
set {
layer.shadowOpacity = newValue
}
get {
return layer.shadowOpacity
}
}
/* The shadow offset. Defaults to (0, -3). Animatable. */
@IBInspectable var shadowOffset: CGPoint {
set {
layer.shadowOffset = CGSize(width: newValue.x, height: newValue.y)
}
get {
return CGPoint(x: layer.shadowOffset.width, y:layer.shadowOffset.height)
}
}
/* The blur radius used to create the shadow. Defaults to 3. Animatable. */
@IBInspectable var shadowRadius: CGFloat {
set {
layer.shadowRadius = newValue
}
get {
return layer.shadowRadius
}
}
func addDropShadowToView() {
layer.masksToBounds = false
layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.25).cgColor
layer.shadowOffset = CGSize(width: 2.5, height: 3.3)
layer.shadowRadius = 3.3
layer.shadowOpacity = 1.0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment