UIView with shadow

心已入冬 提交于 2019-12-20 12:36:22

问题


I'm trying to create a shadow around a simple UIView object which is added on top of a UIViewController's view. what's the most straight forward way of doing this?


回答1:


First, be sure to import the Quartz Core library:

#import <QuartzCore/QuartzCore.h>

Next, add the following lines to set up the shadow's properties:

someView.layer.shadowColor = [[UIColor blackColor] CGColor];
someView.layer.shadowOffset = CGSizeMake(10.0f,10.0f);
someView.layer.shadowOpacity = .5f;
someView.layer.shadowRadius = 10.0f;

Keep in mind that if you have that view's clipsToBounds property set to YES, the shadow won't appear.




回答2:


It took me some time to figure it out. Code works perfect but you should import quartz

#import <QuartzCore/QuartzCore.h>


来源:https://stackoverflow.com/questions/4887771/uiview-with-shadow

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