方法一:
//加陰影
_imageView.layer.shadowOffset = CGSizeMake(4,4);//shadowOffset陰影偏移,x向右偏移4凑阶,y向下偏移4,默認(rèn)(0, -3),這個跟shadowRadius配合使用
_imageView.layer.shadowOpacity = 0.8;//陰影透明度,默認(rèn)0
_imageView.layer.shadowRadius = 4;//陰影半徑嘁扼,默認(rèn)3
方法二:
// 路徑陰影
_imageView1.layer.shadowColor = [UIColor yellowColor].CGColor;//shadowColor陰影顏色
_imageView1.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset陰影偏移,默認(rèn)(0, -3),這個跟shadowRadius配合使用
_imageView1.layer.shadowOpacity = 1;//陰影透明度黔攒,默認(rèn)0
_imageView1.layer.shadowRadius = 3;//陰影半徑趁啸,默認(rèn)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];
//設(shè)置陰影路徑
_imageView1.layer.shadowPath = path.CGPath;
摘自:http://blog.csdn.net/rhljiayou/article/details/10178723
路徑陰影性能更好