Solid Shadow in All Directions

I’ve been looking for a way to set the shadow property of a layer, like this: enter image description here

where the light blue is the layer—the UIImageView in this instance—and the dark blue is the shadow.

  • How to retrieve number of hours past midnight from an NSDate object?
  • UIImage meta data
  • how to send Asynchronous URL Request?
  • Why do I keep getting this error for my bridging Header in Xcode 7: Bridging Header does not exsist?
  • weak or strong for IBOutlet and other
  • Add image to a navigationItem's title
  • I’d like the shadow to do things:

    • Appear on all four sides: accomplished by setting shadowOffset to CGSizeMake(0.0, 0.0) and making shadowRadius nonzero
    • Be entirely opaque: accomplished by setting shadowOffset to a specific point in the layer and shadowRadius to zero

    I already have shadowOpacityset to zero, but I can’t find a way to do both of these. For example, if I have:

    imageView.layer.shadowColor = UIColor.orangeColor().CGColor
    imageView.layer.shadowOffset = CGSizeMake(4.0 , 4.0)
    imageView.layer.shadowOpacity = 1;
    imageView.layer.shadowRadius = 0
    imageView.layer.masksToBounds = false
    

    I get a solid shadow on two sides. If I want the shadow to be on all four sides, I change shadowOffset to a specific size and shadowRadius to something greater than zero, but then it’s not solid.

    Solutions Collect From Internet About “Solid Shadow in All Directions”

    An alternative option is to use borderWidth and borderColor. Keep in mind that, as mentioned in the docs, borders are drawn inside the layer bounds, rather than extending outside, so you may need to adjust its size as appropriate.

    (Depending on your use case, you might consider using UIImageView with insets to make a stretchable image, which may have different performance characteristics if your layer is being resized.)