iPhone之为UIView设置阴影(CALayer的shadowColor,shadowOffset,shadowOpacity,shadowRadius,shadowPath属性)
效果图:
以下代码实现:
第一个图片的代码
//加阴影--任海丽编辑
_imageView.layer.shadowColor = [UIColor blackColor].CGColor;//shadowColor阴影颜色
_imageView.layer.shadowOffset = CGSizeMake(4,4);//shadowOffset阴影偏移,x向右偏移4,y向下偏移4,默认(0, -3),这个跟shadowRadius配合使用
_imageView.layer.shadowOpacity = 0.8;//阴影透明度,默认0
_imageView.layer.shadowRadius = 4;//阴影半径,默认3
第二个图片的代码
_imageView1.layer.shadowColor = [UIColor yellowColor].CGColor;//shadowColor阴影颜色
_imageView1.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset阴影偏移,默认(0, -3),这个跟shadowRadius配合使用
_imageView1.layer.shadowOpacity = 1;//阴影透明度,默认0
_imageView1.layer.shadowRadius = 3;//阴影半径,默认3 //路径阴影
UIBezierPath *path = [UIBezierPath bezierPath]; float width = _imageView1.bounds.size.width;
float height = _imageView1.bounds.size.height;
float x = _imageView1.bounds.origin.x;
float y = _imageView1.bounds.origin.y;
float addWH = 10; CGPoint topLeft = _imageView1.bounds.origin;
CGPoint topMiddle = CGPointMake(x+(width/2),y-addWH);
CGPoint topRight = CGPointMake(x+width,y); CGPoint rightMiddle = CGPointMake(x+width+addWH,y+(height/2)); CGPoint bottomRight = CGPointMake(x+width,y+height);
CGPoint bottomMiddle = CGPointMake(x+(width/2),y+height+addWH);
CGPoint bottomLeft = CGPointMake(x,y+height); CGPoint leftMiddle = CGPointMake(x-addWH,y+(height/2)); [path moveToPoint:topLeft];
//添加四个二元曲线
[path addQuadCurveToPoint:topRight
controlPoint:topMiddle];
[path addQuadCurveToPoint:bottomRight
controlPoint:rightMiddle];
[path addQuadCurveToPoint:bottomLeft
controlPoint:bottomMiddle];
[path addQuadCurveToPoint:topLeft
controlPoint:leftMiddle];
//设置阴影路径
_imageView1.layer.shadowPath = path.CGPath;
ok!
iPhone之为UIView设置阴影(CALayer的shadowColor,shadowOffset,shadowOpacity,shadowRadius,shadowPath属性)的更多相关文章
- UIView 设置阴影(属性说明)
以下代码实现: 第一个图片的代码 //加阴影--任海丽编辑 _imageView.layer.shadowColor = [UIColor blackColor].CGColor;//shadowCo ...
- UIView设置阴影
UI设计师有时候希望我们的产品比较酷. 阴影是他们喜欢的效果之一. 怎么设置阴影呢? 1.设置一个四边都相同的阴影 UIImageView *testImgView = [[UIImageView a ...
- 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) ...
- UICollectionViewCell设置阴影
//@mg:masksToBounds必须为NO否者阴影没有效果 // cell.layer.masksToBounds = NO; cell.layer.contentsScale = [UIScr ...
- 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> ...
随机推荐
- Android抓包工具Fiddler抓取数据
1.手机端设置 2.Fiddler设置监听 Tools/Fiddler options 是否允许监听到https(Fiddler默认只抓取http格式的),首次点击会弹出是否信任fiddler证书和安 ...
- redis+keeplived分布式缓存
redis(三)redis+Keepalived主从热备秒级切换 博客分类: 分布式缓存Redis redis高可用Keepalived 一 简介 安装使用centos 5.10 Master 19 ...
- sync fsync fdatasync ---systemtap跟踪
aa.stp: probe kernel .function ( "sys_sync" ) { printf ( "probfunc:%s fun:%s\n", ...
- Could not fetch https://api.github.com/repos/RobinHerbots/jquery
使用 composer 安装YII2时, 如题所示提示, 原因是由于yii安装中, 需要有一些相关的认证[或许说是composer的认证], 如有如下提示 Could not fetch https: ...
- Python中利用函数装饰器实现备忘功能
Python中利用函数装饰器实现备忘功能 这篇文章主要介绍了Python中利用函数装饰器实现备忘功能,同时还降到了利用装饰器来检查函数的递归.确保参数传递的正确,需要的朋友可以参考下 " ...
- ST表poj3264
/* ST表多次查询区间最小值 设 g[j][i] 表示从第 i 个数到第 i + 2 ^ j - 1 个数之间的最小值 类似DP的说 ans[i][j]=min (ans[i][mid],ans ...
- UniqueID和ClientID的来源
在<漫话ID>一文中,作者提出了一个问题:为什么在ItemCreated事件中访问ClientID会导致MyButton无法响应事件,事实上 MyButton无法响应事件是因为他在客户端的 ...
- My.Ioc 代码示例——如何使用默认构造参数,以及如何覆盖默认构造参数
在 Ioc 世界中,有些框架(例如 Autofac/NInject/Unity)支持传递默认参数,有些框架(例如 SimpleInjector/LightInjector 等)则不支持.作为 My.I ...
- ManagementException:WMI异常处理介绍
.NET调用WMI后无论是同步调用还是异步调用,都会产生返回一个int类型的执行结果.如果成功,则返回0.如果不是0,则有对应错误码表示发生了什么错误. 根据咱们这个系列的博文,我总结了关于进程,服务 ...
- 使用第三方框架 Masonry 实现自动布局
使用第三方框架 Masonry 实现自动布局 时间:2015-02-10 11:08:41 阅读:4595 评论:0 收藏:0 [点我收藏+] 标签: 由于前两 ...