您的位置:首页 > 其它

贝塞尔曲线

2015-09-01 19:36 381 查看
第一种加载方法

- (void)drawRect:(CGRect)rect {
UIBezierPath *backPath = [UIBezierPath bezierPath];
[backPath moveToPoint:CGPointMake(0, 0)];
[backPath addLineToPoint:CGPointMake(0, rect.size.height)];
[backPath addLineToPoint:CGPointMake(rect.size.width, rect.size.height)];
[backPath addLineToPoint:CGPointMake(rect.size.width, 0)];
[backPath closePath];
[self.superview.backgroundColor set];
[backPath fill];

CGFloat width = MIN(CGRectGetWidth(rect), CGRectGetHeight(rect));
CGFloat lineW = 3 / [UIScreen mainScreen].scale;

UIBezierPath *backProPath = [UIBezierPath bezierPath];
[backProPath addArcWithCenter:CGPointMake(width / 2., width / 2.) radius:width / 2. - 10 startAngle:0 endAngle:M_PI * 2 clockwise:true];
backProPath.lineWidth = lineW;
[[UIColor grayColor] set];
[backProPath stroke];

UIBezierPath *progressPath = [UIBezierPath bezierPath];
[progressPath addArcWithCenter:CGPointMake(width / 2., width / 2.) radius:width / 2. - 10 startAngle:0 endAngle:M_PI_4 clockwise:true];
progressPath.lineWidth = lineW;
[[UIColor redColor] set];
[progressPath stroke];
}


第二种加载方法

- (void)drawRect:(CGRect)rect {
UIBezierPath *tempPath = [UIBezierPath bezierPathWithRect:rect];
[self.superview.backgroundColor set];
[tempPath fill];

CGFloat width = MIN(CGRectGetWidth(rect), CGRectGetHeight(rect));

CAShapeLayer *backLayer = [CAShapeLayer layer];

backLayer.lineWidth = 3 / [UIScreen mainScreen].scale;
backLayer.strokeColor = [UIColor cyanColor].CGColor;
backLayer.fillColor = [UIColor redColor].CGColor;

[self.layer addSublayer:backLayer];

UIBezierPath *backPath = [UIBezierPath bezierPath];
[backPath addArcWithCenter:CGPointMake(width / 2., width / 2.) radius:width / 2. - 3 startAngle:0 endAngle:M_PI_4 clockwise:true];

backLayer.path = backPath.CGPath;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: