Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a Shadow to a NSImageView

I have a NSImageView and want to add a shadow. I've tried doing it programmatically with:

NSShadow *shadow = [[[NSShadow alloc] init] autorelease];
[shadow setShadowBlurRadius:4.0f];
[shadow setShadowOffset:CGSizeMake(4.0f, 4.0f)];
[shadow setShadowColor:[NSColor blackColor]];

[view setShadow:shadow];

But it won't appear. Any ideas? Thanks.

like image 408
Kevin Sylvestre Avatar asked Jan 16 '11 05:01

Kevin Sylvestre


2 Answers

You have to set the parameters of the shadow. By default, it's all zeroes, so it has no visible effect on a view.

See -setShadowColor:, -setShadowRadius:, and -setShadowOffset: on NSShadow, I believe.

like image 118
Jonathan Grynspan Avatar answered Oct 15 '22 10:10

Jonathan Grynspan


Swift 4

let shadow = NSShadow()
shadow.shadowOffset = NSMakeSize(2, -2)
shadow.shadowColor = NSColor.lightGray
shadow.shadowBlurRadius = 3

imageView.wantsLayer = true
imageView.shadow = shadow
like image 2
Confused Vorlon Avatar answered Oct 15 '22 11:10

Confused Vorlon