views:

835

answers:

2

I would like to add a drop shadow to a UIButton. I tried to use self.layer.shadow* properties. Those properties work in UIView, but they behave differently in UIButton. I would really appreciate it if I could get any pointers to draw the drop shadow. Thank you!

self.layer.cornerRadius = 8.0f;
self.layer.masksToBounds = YES;
self.layer.borderWidth = 1.0f;

self.layer.shadowColor = [UIColor greenColor].CGColor;
self.layer.shadowOpacity = 0.8;
self.layer.shadowRadius = 12;
self.layer.shadowOffset = CGSizeMake(12.0f, 12.0f);
A: 

You can subclass UIButton and overwrite the drawRect: method and add manually a drop shadow. That's much more work and you should now a few things about quartz 2d, but the result is exactly what you want. Otherwise you could just add an image, but I prefere to subclass UIButton, because it is very flexible regarding the size of the button, it's more general.

burki
+1  A: 

The Core Animation Guide, http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CoreAnimation_guide/Articles/LayerVisProps.html, says:

iPhone OS Note: As a performance consideration, iPhone OS does not support the shadowColor, shadowOffset, shadowOpacity, and shadowRadius properties.

Dang.

d_CFO
This properties are now supported since iOS 3.2.Regards,
Quentin