prior swift 3 i was adding shadow in my UIView like this :
//toolbar is an UIToolbar (UIView)
toolbar.layer.masksToBounds = false
toolbar.layer.shadowOffset = CGSize(width: -1, height: 1)
toolbar.layer.shadowRadius = 1
toolbar.layer.shadowOpacity = 0.5
but the above code is not working in swift 3 , instead of shadow my whole View's color is turned to ugly gray
anyone knows how can we add shadow in swift 3 ?
Very simple and few lines of code:
Look like :![enter image description here](https://i.stack.imgur.com/cKJkJ.png)
If you need rounded shadow. Works for swift 4.2
Swift 4 rounded UIView with shadow
CODE SNIPPET:
OUTPUT 1:
OUTPUT 2:
If you want to use it as a IBInspectable property for your views you can add this extension
I would like to add one more line with selected answer! When we rasterizing the layer, It needs to be set to 2.0 for retina displays. Otherwise label text or images on that view will be blurry. So we need to add
rasterizationScale
also.