//
// ZendaiProgressChartView.m
// DrawCircle
//
// Created by ios on 15/4/22.
// Copyright (c) 2015年 ios. All rights reserved.
//
#import "ZendaiProgressChartView.h"
@implementation ZendaiProgressChartView
-(void)setProgress:(CGFloat)progress
{
_progress=progress;
[self setNeedsDisplay];
}
// 覆盖drawRect方法,你可以在此自定义绘画和动画
- (void)drawRect:(CGRect)rect
{
self.backgroundColor=COLOR_MAKE(100.0, 168.0, 72.0);
// self.backgroundColor=[UIColor clearColor];
CGFloat R=rect.size.width>rect.size.height?rect.size.height*0.8/2:rect.size.width*0.8/2;
CGPoint center=CGPointMake(rect.size.width/2, rect.size.height/2);
CGFloat singel=-M_PI_2+_progress*2*M_PI/100;
//An opaque type that represents a Quartz 2D drawing environment.
//一个不透明类型的Quartz 2D绘画环境,相当于一个画布,你可以在上面任意绘画
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextRef imgCtx = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(imgCtx, center.x, center.y);
CGContextSetFillColor(imgCtx, CGColorGetComponents([UIColor colorWithRed:117.0/255.0 green:180.0/255.0 blue:94.0/255.0 alpha:1].CGColor));
CGContextAddArc(imgCtx, center.x, center.y, R-15, -M_PI/2,singel, 0);
CGContextFillPath(imgCtx);
CGContextSetRGBStrokeColor(context,1,1,1,1.0);//画笔线的颜色
CGContextSetLineWidth(context, 8.0);//线的宽度
//void CGContextAddArc(CGContextRef c,CGFloat x, CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle, int clockwise)1弧度=180°/π (≈57.3°) 度=弧度×180°/π 360°=360×π/180 =2π 弧度
// x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle为 结束的弧度,clockwise 0为顺时针,1为逆时针。
CGContextAddArc(context, center.x, center.y, R-15,0,2*M_PI, 0); //添加一个圆
CGContextDrawPath(context, kCGPathStroke); //绘制路径
CGContextSetRGBStrokeColor(context,1,1,1,1.0);//画笔线的颜色
CGContextSetLineWidth(context,1.0);//线的宽度
//void CGContextAddArc(CGContextRef c,CGFloat x, CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle, int clockwise)1弧度=180°/π (≈57.3°) 度=弧度×180°/π 360°=360×π/180 =2π 弧度
// x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle为 结束的弧度,clockwise 0为顺时针,1为逆时针。
CGContextAddArc(context, center.x, center.y, R,0,2*M_PI, 0); //添加一个圆
CGContextDrawPath(context, kCGPathStroke); //绘制路径
//
CGContextRef cirCtx = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(cirCtx, (center.x+cosf(singel) * R), (center.y+sinf(singel) * R));
CGContextSetFillColor(cirCtx, CGColorGetComponents([UIColor colorWithRed:254.0/255.0 green:254.0/255.0 blue:254.0/255.0 alpha:1].CGColor));
CGContextAddArc(cirCtx, (center.x+cosf(singel) * R), (center.y+sinf(singel) * R), 4, 0, -2*M_PI, 1);
CGContextFillPath(cirCtx);
}
@end
#import <UIKit/UIKit.h>
@interface ZendaiProgressCircleView : UIView
@property(nonatomic,assign)CGFloat progress;
@end
//
// ZendaiProgressCircleView.m
// DrawCircle
//
// Created by ios on 15/4/22.
// Copyright (c) 2015年 ios. All rights reserved.
//
#import "ZendaiProgressCircleView.h"
@implementation ZendaiProgressCircleView
-(void)setProgress:(CGFloat)progress
{
_progress=progress;
[self setNeedsDisplay];
}
// 覆盖drawRect方法,你可以在此自定义绘画和动画
- (void)drawRect:(CGRect)rect
{
self.backgroundColor=[UIColor clearColor];
CGFloat R=rect.size.width>rect.size.height?rect.size.height*0.9/2:rect.size.width*0.9/2;
CGPoint center=CGPointMake(rect.size.width/2, rect.size.height/2);
CGFloat singel=_progress*2*M_PI/100-M_PI/2;
//An opaque type that represents a Quartz 2D drawing environment.
//一个不透明类型的Quartz 2D绘画环境,相当于一个画布,你可以在上面任意绘画
CGContextRef context = UIGraphicsGetCurrentContext();
//边框圆
CGContextSetRGBStrokeColor(context,1,1,1,1.0);//画笔线的颜色
CGContextSetLineWidth(context, 2.0);//线的宽度
//void CGContextAddArc(CGContextRef c,CGFloat x, CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle, int clockwise)1弧度=180°/π (≈57.3°) 度=弧度×180°/π 360°=360×π/180 =2π 弧度
// x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle为 结束的弧度,clockwise 0为顺时针,1为逆时针。
CGContextAddArc(context, center.x, center.y, R-3.5,0,2*M_PI, 0); //添加一个圆
CGContextDrawPath(context, kCGPathStroke); //绘制路径
CGContextSetRGBStrokeColor(context,1,1,1,1.0);//画笔线的颜色
CGContextSetLineWidth(context, 6.0);//线的宽度
//void CGContextAddArc(CGContextRef c,CGFloat x, CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle, int clockwise)1弧度=180°/π (≈57.3°) 度=弧度×180°/π 360°=360×π/180 =2π 弧度
// x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle为 结束的弧度,clockwise 0为顺时针,1为逆时针。
CGContextAddArc(context, center.x, center.y, R,-M_PI_2,singel, 0); //添加一个圆
CGContextDrawPath(context, kCGPathStroke); //绘制路径
}
@end