美文网首页
UIBezierPath(二)

UIBezierPath(二)

作者: Nbm | 来源:发表于2018-11-22 18:05 被阅读54次

    下载进度

    -(void)drawRect:(CGRect)rect
    {
        //这个方法只会走一次,不能h手动调用此方法,只有系统能l开启图形上下文
        CGPoint center = CGPointMake(rect.size.width/2, rect.size.height/2);
        
        UIBezierPath * path = [UIBezierPath bezierPathWithArcCenter:center radius:rect.size.width/2 -5 startAngle:-M_PI_2 endAngle:-M_PI_2 + self.progressValue *M_PI*2 clockwise:YES];
        
        path.lineWidth = 2;
        
        [[UIColor redColor] setStroke];
        
        [path stroke];
        
        
        
    }
    
    进度条

    饼状图

    -(void)drawRect:(CGRect)rect
    {
        NSArray * array = [self randomArray];
    
        CGFloat radius = rect.size.width/2;
        CGPoint center = CGPointMake(radius, radius);
        CGFloat start =0;
        CGFloat end =0;
        CGFloat angle =0;
        
        for (int i=0; i<array.count; i++) {
            
             start = end;
             angle = [array[i] doubleValue]/100.0 * M_PI *2;
             end = start + angle;
            UIBezierPath * path = [UIBezierPath bezierPathWithArcCenter:center radius:radius-6 startAngle:start endAngle:end clockwise:YES];
            [path addLineToPoint:center];
            [[self randomColor] set];
            [path fill];
            
            
            
        }
        
    }
    
    饼状图

    相关文章

      网友评论

          本文标题:UIBezierPath(二)

          本文链接:https://www.haomeiwen.com/subject/tnalqqtx.html