UIView设置阴影
UI设计师有时候希望我们的产品比较酷。
阴影是他们喜欢的效果之一。
怎么设置阴影呢?
1、设置一个四边都相同的阴影
UIImageView *testImgView = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )]; [testImgView setBackgroundColor:[UIColor yellowColor]]; // 阴影颜色
testImgView.layer.shadowColor = [UIColor blackColor].CGColor;
// 阴影偏移,默认(0, -3)
testImgView.layer.shadowOffset = CGSizeMake(,);
// 阴影透明度,默认0
testImgView.layer.shadowOpacity = 0.5;
// 阴影半径,默认3
testImgView.layer.shadowRadius = ; [self.view addSubview:testImgView];
效果如图:
2、设置单边阴影
//单边阴影 UILabel *testLabel = [[UILabel alloc]initWithFrame:CGRectMake(, , , )]; [testLabel setBackgroundColor:[UIColor yellowColor]]; // 阴影颜色
testLabel.layer.shadowColor = [UIColor blackColor].CGColor; // 阴影偏移,默认(0, -3)
testLabel.layer.shadowOffset = CGSizeMake(,); // 阴影透明度,默认0
testLabel.layer.shadowOpacity = 0.5;
// 阴影半径,默认3
testLabel.layer.shadowRadius = ; // 单边阴影 顶边
float shadowPathWidth = testLabel.layer.shadowRadius; CGRect shadowRect = CGRectMake(-shadowPathWidth/2.0, -shadowPathWidth/2.0, testLabel.bounds.size.width+shadowPathWidth, shadowPathWidth); UIBezierPath *path = [UIBezierPath bezierPathWithRect:shadowRect];
testLabel.layer.shadowPath = path.CGPath; [self.view addSubview:testLabel];
效果如下:
3、和阴影相关的属性
/** Shadow properties. **/ /* The color of the shadow. Defaults to opaque black. Colors created
* from patterns are currently NOT supported. Animatable. */ @property(nullable) CGColorRef shadowColor; /* The opacity of the shadow. Defaults to 0. Specifying a value outside the
* [0,1] range will give undefined results. Animatable. */ @property float shadowOpacity; /* The shadow offset. Defaults to (0, -3). Animatable. */ @property CGSize shadowOffset; /* The blur radius used to create the shadow. Defaults to 3. Animatable. */ @property CGFloat shadowRadius; /* When non-null this path defines the outline used to construct the
* layer's shadow instead of using the layer's composited alpha
* channel. The path is rendered using the non-zero winding rule.
* Specifying the path explicitly using this property will usually
* improve rendering performance, as will sharing the same path
* reference across multiple layers. Upon assignment the path is copied.
* Defaults to null. Animatable. */ @property(nullable) CGPathRef shadowPath;
UIView设置阴影的更多相关文章
- iPhone之为UIView设置阴影(CALayer的shadowColor,shadowOffset,shadowOpacity,shadowRadius,shadowPath属性)
效果图: 以下代码实现: 第一个图片的代码 //加阴影--任海丽编辑 _imageView.layer.shadowColor = [UIColor blackColor].CGColor;//sha ...
- UIView 设置阴影(属性说明)
以下代码实现: 第一个图片的代码 //加阴影--任海丽编辑 _imageView.layer.shadowColor = [UIColor blackColor].CGColor;//shadowCo ...
- UIView设置阴影无效的原因之一
本想在底部的按钮设置个阴影, 代码如下: self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowOffset ...
- swift 设置阴影和圆角
1.正常view设置阴影 func setShadow(view:UIView,sColor:UIColor,offset:CGSize, opacity:Float,radius:CGFloat) ...
- div四个边框分别设置阴影样式
对于div边框的阴影一直没有很好地理解,也一直不明白怎么给四个边框分别设置阴影.昨天项目中碰到了这个问题,就认真想了一下,在此总结一二. 首先,还是从官方解释说起. 网上的解释通常都是什么水平阴影长度 ...
- iOS UIView设置圆角
UIView设置圆角 1.比较简单的情况,UIView四个角都是圆角: UIView *aView = [[UIView alloc] init]; aView.frame = CGRectMake( ...
- UIView设置背景渐变色
UIView设置背景渐变色 // Allocate bitmap context CGContextRef bitmapContext = CGBitmapContextCreate(NULL, , ...
- 使文字在div中水平和垂直居中的的css样式为,四个边分别设置阴影样式
text-align:center; /*水平居中*/ line-height: 20px; /*行距设为与div高度一致*/ HTML元素 <div>水平垂直居中</div> ...
- IOS UIView圆角,阴影,边框,渐增光泽
圆角 sampleView.layer.cornerRadius = 2.5; // 圓角的弧度sampleView.layer.masksToBounds = YES; 阴影 sampleView. ...
随机推荐
- FCC---CSS Flexbox: Apply the flex-direction Property to Create a Column in the Tweet Embed
The tweet embed header and footer used the flex-direction property earlier with a row value. Similar ...
- CodeForces - 519D(思维+前缀和)
题意 https://vjudge.net/problem/CodeForces-519D 给定每个小写字母一个数值,给定一个只包含小写字母的字符串 s,求 s 的子串 t 个数,使 t满足: 首位字 ...
- 删除列表中重复元素以及求list中元素个数
Python 去除列表中重复的元素 来自比较容易记忆的是用内置的set l1 = ['b','c','d','b','c','a','a'] l2 = list(set(l1)) print l2 还 ...
- 备份下ESP8266的AT指令集手册和用例手册中文版,准备为V7做几个ESP8266的例子
指令集手册:https://files.cnblogs.com/files/armfly/4a-esp8266_at_instruction_set_cn.rar 用例手册: https://file ...
- js的cookies及html5的localStorage、sessionStorage
1.首先,理解什么是cookies? cookies:存储在客户端,数据量小的,会过期的数据,以字符串形式存储 cookie操作代码示例: <script> window.onload = ...
- (一)初识NumPy库(数组的创建和变换)
在学习数据分析时,NumPy作为最基础的数据分析库,我们能够熟练的掌握它是学习数据分析的必要条件.接下来就让我们学习该库吧. 学习NumPy库的环境: python:3.6.6 编辑器:pycharm ...
- SpringBoot系列-整合Mybatis(注解方式)
目录 一.常用注解说明 二.实战 三.测试 四.注意事项 上一篇文章<SpringBoot系列-整合Mybatis(XML配置方式)>介绍了XML配置方式整合的过程,本文介绍下Spring ...
- 文件上传报错:Unknown: file created in the system's temporary directory
nginx+php下文件上传成功,但会有错误提示如下: <b>Notice</b>: Unknown: file created in the system's tempor ...
- RSA加解密&RSA加验签详解
RSA 加密算法是目前最有影响力的 公钥加密算法,并且被普遍认为是目前 最优秀的公钥方案 之一.RSA 是第一个能同时用于 加密 和 数字签名 的算法,它能够 抵抗 到目前为止已知的 所有密码攻击,已 ...
- Harbor 清理镜像(此方法比较粗暴,但是有效)
0x00 事件 Harbor 私有仓库中占有的存储慢慢越来越大,使用官方的清理工具以及 UI 上的垃圾清理,都似乎也不能清理掉-- 后来吾用了一种简单粗暴的方法清理镜像--删除 harbor regi ...