UIView与阴影 [英] UIView with shadow

查看:98
本文介绍了UIView与阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个简单的UIView对象周围创建一个阴影,它添加在UIViewController的视图顶部。
这是最直接的方法是什么?

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?

推荐答案

首先,确保导入Quartz Core库:

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;

请记住,如果您将该视图的clipsToBounds属性设置为YES, 。

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

这篇关于UIView与阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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