iOS - 阴影 、 路径阴影

方法一:
//加阴影

    _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;  

摘自:http://blog.csdn.net/rhljiayou/article/details/10178723

路径阴影性能更好

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 179,764评论 25 708
  • 在此特此声明:一下所有链接均来自互联网,在此记录下我的查阅学习历程,感谢各位原创作者的无私奉献 ! 技术一点一点积...
    远航的移动开发历程阅读 11,587评论 12 197
  • 这个主题的内容之前分三个篇幅分享过,导致网络上传播的比较分散,所以本篇做了一个汇总,同时对部分内容及答案做了修改,...
    JavaQ阅读 23,924评论 9 264
  • 我的孩子7岁,二年级,他很阳光,开朗,真挚,我很欣慰,更庆幸自己能陪他一起成长。在我心里,他的童年比我幸福一万倍。...
    秋之初心阅读 251评论 0 0
  • 泪痕未干 残酒断盏 酒醉一场将告别声断 夜已过半 月正高悬 刀锋冰冷我起身回转 策马而行不忍听你轻声呢喃 衣袂飘 ...
    青猫拾叶阅读 536评论 2 8

友情链接更多精彩内容