我想在自定义视图中添加几个点,创建路径,关闭它并填充颜色。在for循环中,我水平放置几千个点并用线连接它们。但是,我无法画出近距离的bezier路径。问题是什么?
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, screenHeight/2)];
[path addLineToPoint:CGPointMake(0, screenHeight/2)];
[path addLineToPoint:CGPointMake(0, screenHeight/2)];
for (int i=0; i<=screenWidth; i+=screenWidth/stepNo) {
[path addLineToPoint:CGPointMake(i, screenHeight/2)];
}
[path addLineToPoint:CGPointMake(screenWidth, screenHeight/2)];
[path addLineToPoint:CGPointMake(screenWidth, screenHeight)];
[path addLineToPoint:CGPointMake(0, screenHeight)];
[path closePath];
//Create a CAShapeLayer that uses that UIBezierPath:
CAShapeLayer *shape = [CAShapeLayer layer];
shape.path = path.CGPath;
shape.fillColor = [UIColor colorWithRed:255/255.0 green:20/255.0 blue:147/255.0 alpha:1].CGColor;
// 5
[self.view.layer addSublayer:shape];