码迷,mamicode.com
首页 > 其他好文 > 详细

贝塞尔曲线

时间:2015-09-01 21:30:22      阅读:259      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!