jeremyabannister
jeremyabannister

Reputation: 4386

Swift - Where is shadowOpacity on NSShadow?

I just discovered the unfortunate fact that setting the shadow properties of an NSView's backing layer on macOS does not cause the shadow to render. It seems that this only works for stand-alone layers. I then found out about NSShadow and I gave it a try and at least the shadow renders. But why does NSShadow not provide any API for shadowOpacity? It only has offset, blur radius and color. How do I control the darkness of the shadow with NSShadow?

If someone could tell me how to get the CALayer shadow to render even though the layer is the backing layer of an NSView that would be even better for me. Thanks very much.

Upvotes: 1

Views: 402

Answers (1)

Loengard
Loengard

Reputation: 431

Yes, setting .withAplhaComponent will work, but to show a view's layer's shadow you can either:

view.layer?.masksToBounds = false
view.layer?.shadowOpacity = 0.7

or show the view's superview's layer's shadow:

view.superview?.layer?.shadowOpacity = 0.7

Upvotes: 0

Related Questions