Quartz 2 Dの進捗バー、円グラフ、柱状図
2155 ワード
Quartz 2 D実戦は、前の図面の基礎知識を学び、進捗バー、円グラフ、柱状図など、複雑な図形の描画を行うことができます.
進捗バープログレスバーを描画するには、描画された円弧 を制御することが重要です.
円グラフケーキ図と描画進捗バーはよく似ています 重要なのは、各部分の弧度がどのように計算されるか である.
柱状図柱図は、矩形 を描画することである.柱図を描く上で最も重要なのは、描画されたCGRect を計算することである.
進捗バー
//
CGFloat radius = rect.size.width * 0.5;
CGPoint center = CGPointMake(radius, radius);
CGFloat endA = -M_PI_2 + _progress * M_PI * 2;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius - 2 startAngle:-M_PI_2 endAngle:endA clockwise:YES];
//
//[[UIColor greenColor] set];
//
//path.lineWidth = 3;
//
//[path addLineToPoint:center];
[path stroke];
円グラフ
CGFloat radius = self.bounds.size.width * 0.5;
CGPoint center = CGPointMake(radius, radius);
CGFloat startA = 0;
CGFloat angle = 0;
CGFloat endA = 0;
//
angle = 0.25 * M_PI * 2;
endA = startA + angle;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
//
[path addLineToPoint:center];
//
[[UIColor redColor] set];
[path fill];
//
startA = endA;
angle = 0.25 * M_PI * 2;
endA = startA + angle;
UIBezierPath *path1 = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
//
[path1 addLineToPoint:center];
//
[[UIColor greenColor] set];
[path1 fill];
//
startA = endA;
angle = 0.5 * M_PI * 2;
endA = startA + angle;
UIBezierPath *path2 = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
//
[path2 addLineToPoint:center];
//
[[UIColor blueColor] set];
[path2 fill];
柱状図
//
CGRect rectt = CGRectMake(0, 0, 20, 100);
UIBezierPath *path = [UIBezierPath bezierPathWithRect:rectt];
[[UIColor redColor] set];
[path fill];