How can I draw a shadow beyond a UIView's bounds?

心已入冬 提交于 2019-12-04 20:33:47

It is not encouraged to draw outside view bounds. Maybe you can include the shadow directly in your background...

Regards,

Instead of manual drawing in drawRect, consider setting properties on the the UIView's Core Animation layer for drawing a shadow.

For example:

[descriptionInput setClipsToBounds:NO];
[descriptionInput.layer setShadowColor:[[UIColor blackColor] CGColor]];
[descriptionInput.layer setShadowOpacity:0.8];
[descriptionInput.layer setShadowOffset:CGSizeMake(0.0, 3.0)];

For this to work, you need to include QuartzCore:

#import <QuartzCore/QuartzCore.h>

clipsToBounds only controls the clipping for children of a view, not drawing of that view itself; hence it's not solving your problem.

If you can draw your shadow onto a different view and add that as a child, it won't get clipped. However, I don't know how possible that is with the method you're using :(

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!