UIButton shadow not looking right

I'm trying to add a shadow to a UIButton layer, but for some reason it cuts off at the bounds of the button. I set clipsToBounds is turned off, so I'm not sure why it's looking like this:

It's square, just like that, even though the shadow should not be squared..it should be soft and fading.

button.clipsToBounds = NO;
button.layer.masksToBounds = NO;
button.layer.shadowOffset = CGSizeZero;
button.layer.shadowPath = [UIBezierPath bezierPathWithRect:button.layer.bounds].CGPath;
button.layer.shadowOpacity = 0.7;
button.layer.shadowColor = [UIColor blackColor].CGColor;
button.layer.shadowRadius = 10;

Am I missing anything?

Oh, and my button is a subclass of UIButton. I'm not sure if that makes a difference.. -Even with a shadowRadius of 0.0, I get a fully visible black square as my shadow


clipsToBounds will allow any child views to be drawn outside the bounds of your button.

Looks like it doesn't apply to your layer though :(

You might just have to make your button a bit bigger (or your shadow smaller!)

链接地址: http://www.djcxy.com/p/74242.html

上一篇: NSScrollView:淡入顶部

下一篇: UIButton阴影不正确