UIView设置阴影

UIView设置阴影CALayer的属性:

shadowColor,

shadowOffset,

shadowOpacity,

shadowRadius,

shadowPath

 加阴影
//shadowColor阴影颜色
_imageView.layer.shadowColor = [UIColor blackColor].CGColor;
/**
shadowOffset阴影偏移,x向右偏移4,y向下偏移4,默认(0, -3),这个跟shadowRadius配合使用
*/
_imageView.layer.shadowOffset = CGSizeMake(4,4);
//阴影透明度,默认0
  _imageView.layer.shadowOpacity = 0.8;
//阴影半径,默认3
 _imageView.layer.shadowRadius = 4;  
   //shadowColor阴影颜色
 _imageView1.layer.shadowColor = [UIColor yellowColor].CGColor;
   shadowOffset阴影偏移,默认(0, -3),这个跟shadowRadius配合使用
  //阴影透明度,默认0
  _imageView1.layer.shadowOffset = CGSizeMake(0,0);
  _imageView1.layer.shadowOpacity = 1;
  // 阴影半径,默认3
 _imageView1.layer.shadowRadius = 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;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 10,519评论 5 13
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 12,712评论 6 30
  • >嗯,圆和椭圆还不错,但如果是带圆角的矩形呢? >我们现在能做到那样了么? >史蒂芬·乔布斯 我们在第三章『图层几...
    夜空下最亮的亮点阅读 3,996评论 0 0
  • 有幸福快乐 也有痛苦 痛苦的是我的需要没有被满足 我想要有人陪伴的时候 我想要被关注被重视被需要 没有被满足 我想...
    周海双阅读 2,994评论 0 0
  • 昨日做下的事: 谈下一个比较重要的合作,也和合伙人说明白一些事情。 队员出量帮忙送卡,把屯的少量卡出完了。 开一节...
    文建伟CZYH阅读 1,066评论 0 0