CALayer的shadowColor,shadowOffset,shadowOpacity,shadowRadius,shadowPath属性


    // 阴影的颜色

    self.shadowview.layer.shadowColor = [UIColor blackColor].CGColor

    // 阴影的偏移量,该示例指向右偏移2, 向下偏移2

    self.shadowview.layer.shadowOffset = CGSizeMake(2, 2);

    // 阴影的透明度 范围为0~1

    self.shadowview.layer.shadowOpacity = 0.4;

    // 阴影的半径 默认为3

    self.shadowview.layer.shadowRadius = 5;


// 以下代码为通过贝塞尔曲线,设置 shadowPath

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;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值