(转载)ios之为UIView设置阴影(CALayer的shadowColor,shadowOffset,shadowOpacity,shadowRadius,shadowPath属性)

简介: 原文地址:http://blog.csdn.net/rhljiayou/article/details/10178723效果图:以下代码实现:第一个图片的代码//加阴影--任海丽编辑 _imageView.

原文地址:http://blog.csdn.net/rhljiayou/article/details/10178723

效果图:


img_845f834c57c952d625945213a6bee21f.jpe

以下代码实现:
第一个图片的代码

//加阴影--任海丽编辑  
    _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!

目录
相关文章
|
10月前
|
iOS开发
iOS CAEmitterLayer 属性介绍
iOS CAEmitterLayer 属性介绍
36 0
|
1月前
|
前端开发 iOS开发
input框设置placeholder属性在iOS中显示不完整
input框设置placeholder属性在iOS中显示不完整
20 1
|
2月前
|
安全 开发者 iOS开发
iOS16系统手机设置开启开发者模式才能安装ipa包
iOS16系统手机设置开启开发者模式才能安装ipa包
76 1
|
2月前
按钮的image图片是非圆角,直接对UIButton设置圆角,iOS13系统没有圆角效果的问题及解决方案
按钮的image图片是非圆角,直接对UIButton设置圆角,iOS13系统没有圆角效果的问题及解决方案
28 0
|
7月前
|
API 开发工具 iOS开发
在应用研发平台EMAS中,ios的推送有没有办法在app端设置在收到通知后是否展示的逻辑
在应用研发平台EMAS中,ios的推送有没有办法在app端设置在收到通知后是否展示的逻辑
50 1
|
iOS开发
iOS - UIView 动画
1、UIView 动画 核心动画 和 UIView 动画 的区别: 核心动画一切都是假象,并不会真实的改变图层的属性值,如果以后做动画的时候,不需要与用户交互,通常用核心动画(转场)。 UIView 动画必须通过修改属性的真实值,才有动画效果。
1137 0
|
iOS开发 Swift
iOS UIView动画详解(Objective-C)
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px">     我在之前的一篇博客中《<a target="_blank" href="http://blog.csdn.net/chenyufeng1991/a
1648 0
|
容器
iOS&amp;nbsp;动画总结—UIView动画
1.概述 UIKit直接将动画集成到UIView类中,实现简单动画的创建过程。UIView类定义了几个内在支持动画的属性声明,当这些属性发生改变时,视图为其变化过程提供内建的动画支持。
815 0