UIView with shadow

2019-03-15 21:21发布

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?

2条回答
爷的心禁止访问
2楼-- · 2019-03-15 22:06

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

#import <QuartzCore/QuartzCore.h>
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-03-15 22:19

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.

查看更多
登录 后发表回答