view的阴影设置

view的阴影属性主要有5个
//shadowColor      //阴影颜色
//shadowOpacity    //阴影不透明度
//shadowRadius     //阴影半径
//shadowOffset     //阴影偏移量 
//shadowPath       //阴影路径
//前四个属性的效果
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(30, 100, self.view.bounds.size.width-60, 200)];
view.backgroundColor = [UIColor whiteColor];
view.layer.shadowColor = [UIColor redColor].CGColor;
view.layer.shadowOpacity = 1;   //阴影不透明度 【0-1】 0->完全透明   1->完全不透明  越大越明显  默认0
view.layer.shadowRadius = 20;       //阴影半径  默认3
view.layer.shadowOffset = CGSizeMake(0, 0); //阴影偏移量 (右,下) 默认(0,-3)
[self.view addSubview:view];
view的阴影设置_第1张图片
效果图

添加以下代码设置贝塞尔曲线

//view.layer.shadowPath  贝塞尔曲线
UIBezierPath *path = [UIBezierPath bezierPath];

float width = view.bounds.size.width;
float height = view.bounds.size.height;
float x = view.bounds.origin.x;
float y = view.bounds.origin.y;
float addWH = 40;

CGPoint topLeft      = view.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];
//设置阴影路径
view.layer.shadowPath = path.CGPath;

[self.view addSubview:view];
view的阴影设置_第2张图片
效果图

你可能感兴趣的:(view的阴影设置)