如何使用 Quartz 2D 向 UIImage 或 UIImageView 添加阴影? [英] How to use Quartz 2D to add drop shadow to an UIImage or UIImageView?

查看:15
本文介绍了如何使用 Quartz 2D 向 UIImage 或 UIImageView 添加阴影?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Quartz 2D 为 UIImageUIImageView 添加投影?

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

有代码示例吗?

推荐答案

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

不要忘记在你的实现中#import <QuartzCore/QuartzCore.h>.

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

添加@Luke 的评论:

Adding in @Luke's comment:

可能会为其他人节省一些时间的小问题,请确保您没有在您的视图上将 layer.masksToBounds 设置为 YES否则阴影不会出现.

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.

这篇关于如何使用 Quartz 2D 向 UIImage 或 UIImageView 添加阴影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆