首页 > 其他 > 详细

贝塞尔曲线

时间:2015-09-01 21:28:03      阅读:347      评论:0      收藏:0      [点我收藏+]

第一种加载方法

- (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;
}

 

贝塞尔曲线

原文:http://www.cnblogs.com/shenhongbang/p/4776667.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!