I have designed UI elements in sketch, and one of them has a shadow with blur 1 and spread 0. I looked at the doc for the views layer property and layer doesnt have anything named spread or blur, or anything equivalent (the only control was merely shadowOpacity) How can control things like blur and spread?
EDIT:
Here are my settings in Sketch :
And here is what I want my shadow to look like:
And here is what it looks like at the moment:
Note, you have to click on the picture to actually see the shadow.
My code is as follows:
func setupLayer(){
view.layer.cornerRadius = 2
view.layer.shadowColor = Colors.Shadow.CGColor
view.layer.shadowOffset = CGSize(width: 0, height: 1)
view.layer.shadowOpacity = 0.9
view.layer.shadowRadius = 5
}
You can try this .... you can play with the values. The
shadowRadius
dictates the amount of blur.shadowOffset
dictates where the shadow goes.My solution based on this post replies: (Swift 3)
This code worked very well for me:
Sketch Shadow Using IBDesignable and IBInspectable in Swift 4
Here's how to apply all 6 Sketch shadow properties to a UIView's layer with near perfect accuracy:
Say we want to represent the following:
You can easily do this via:
or more succinctly:
Example:
Note:
spread
, it hardcodes a path based on thebounds
of the CALayer. If the layer's bounds ever change, you'd want to call theapplySketchShadow()
method again.