利用
UIBezierPath
绘制特定path
,赋值给CAShapeLayer
的path
。修改view的形状
图示:
代码如下:
- (void)viewDidAppera:(BOOL)animated{
[super viewDidAppear: animated];
[self foundUI];
}
- (void)foundUI{
UIView *view1 = [[UIView alloc]init];
view1.frame = CGRectMake(20, 80, self.view.frame.size.width - 40, 200);
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
[self drawSuperView:view1];
}
- (void)drawSuperView:(UIView *)superView{
CGFloat maxY = CGRectGetHeight(superView.frame);
CGFloat maxX = CGRectGetWidth(superView.frame);
CGFloat minX = 0;
UIColor *lineColor = superView.backgroundColor;
[lineColor set];
UIBezierPath *path = [[UIBezierPath alloc]init];
path.lineWidth = 10;
[path moveToPoint:CGPointMake(minX, maxY)];
[path addLineToPoint:CGPointMake(maxX, maxY)];
[path addQuadCurveToPoint:CGPointMake(minX, maxY) controlPoint:CGPointMake(maxX/2, maxY+80)];
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc]init];
shapeLayer.frame = superView.bounds;
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = lineColor.CGColor;
shapeLayer.strokeColor = lineColor.CGColor;
[superView.layer addSublayer:shapeLayer];
}
分解图示:
结束。