问题描述:

I want to add a dropshadow to a button i've drawn in coregraphics. Other than making the button smaller than the frame, (which is messy coding as in future you'll forget about that and wonder why your button isn't the size it should be), what options do i have to draw the shadow? It's a custom shape, too.

网友答案:

The easiest way is to add it to you CALayer:

#include <QuartzCore/QuartzCore.h>

// iOS 4.0 or later
[self.layer setShadowColor:[[UIColor blackColor] CGColor]];
[self.layer setShadowOffset:CGSizeMake(1.0, 1.0)];
[self.layer setShadowOpacity:0.5];
[self.layer setShadowRadius:1.f];

If that won't work for you, let me know and I will post some code CG code.

网友答案:

Assuming I got the question correctly, you're looking for a way to stop clipping of the shadow. This is easy to achieve, assuming you have a view hierarchy in which the shadowed view resides, just turn off clipsToBounds on the superview of the shadowed view (and if needed on the superview's superview).

Be careful though, as there may've been other things your views were clipping and you didn't want to be seen (although normally this shouldn't be a problem).

相关阅读:
Top