开发者

How to use Quartz 2D to add drop shadow to an UIImage or UIImageView?

开发者_如何转开发How do I use Quartz 2D to add drop shadow to an UIImage or UIImageView ?

Any code samples?


imageView.layer.shadowColor = [UIColor blackColor].CGColor;
imageView.layer.shadowOffset = CGSizeMake(0, 1);
imageView.layer.shadowOpacity = 1;
imageView.layer.shadowRadius = 1.0;

Don't forget to #import <QuartzCore/QuartzCore.h> in your implementation.

EDIT:

Adding in @Luke's comment:

Just a little gotcha that might save some other people some time make sure you have not set layer.masksToBounds to YES on your view otherwise the shadow will not appear.


+ (void)addShadowToView:(UIView*)view Color:(UIColor*)color ShadowOffset:(CGSize)offset Radius:(float)radius Opacity:(float)opacity
{
    view.layer.shadowColor = [color CGColor];
    view.layer.shadowOffset = offset;
    view.layer.shadowRadius = radius;
    view.layer.shadowOpacity = opacity;
}

Use:

[calssName addShadowToView:self.navigationController.navigationBar Color:[UIColor blackColor] ShadowOffset:CGSizeMake(1.0f, 0.5f) Radius:1.0 Opacity:0.5];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜