2

I have the strange problem, that I cannot set shadows for my (layer-backed) views anymore since upgrading to 10.8.

NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowColor:[NSColor darkGrayColor]];
[shadow setShadowOffset:NSMakeSize(0.0, -2.0)];
[shadow setShadowBlurRadius:2.0];

[[self imageView] setWantsLayer:YES];
[[self imageView] setShadow:shadow];

This code snippet worked fine in 10.7 Lion, but does not since the OS upgrade.

I have also created a test project, where I only add an image view via IB and set these shadow properties. This does not work either.

I also downloaded Apples sample code named "CocoaSlides" where they also use layer-backed views and NSShadow. It workes fine there, but the calls seem to be the same as mine.

Has anyone already come across this problem? Did you find a solution?

  • 2
    Does self.imageView.superview also "want layer"? – Joshua Nozzi Jul 26 '12 at 14:45
  • The image view is somewhere down the hierachy in a NSScrollView. Down from the documentView all want layers. I specifically told the immediate superview to want the layer, which does not solve the problem. I have a second case, a Xcode-like tab bar, where shadows are drawn in a NSButtonCell. Specifically setting wantsLayer in the buttons superview worked there. – Markus Mühlberger Jul 27 '12 at 05:52
  • I see. You're probably going to need to provide more context in your question. Please edit it and include a more complete description of your hierarchy, the dimensions of the view needing the shadow, and the bounds of its superview. These are all critical factors others need to make sense of this. – Joshua Nozzi Jul 27 '12 at 12:37
  • Refer this post, hope it solves your issue. http://stackoverflow.com/questions/6791116/create-drop-shadow-for-nsview-cocoa/15216388#15216388 – Sathish Kumar Mar 05 '13 at 05:35

0 Answers0