3

重複の可能性:
円から円へのセグメントの衝突

iOS開発初心者です。このhttp://www.hoodshomecenters.com/product_images/v/723/QuarterRound__65714_zoom.jpgのような画像を CoreGraphic で描画する方法を知っていますか?

4

3 に答える 3

12

円弧部分を描画するコードです。描画したら、その中に線を引くことができます。

#include <math.h>

CGFloat radius = 100;

CGFloat starttime = M_PI/6; //1 pm = 1/6 rad
CGFloat endtime = M_PI;  //6 pm = 1 rad

//draw arc
CGPoint center = CGPointMake(radius,radius);
UIBezierPath *arc = [UIBezierPath bezierPath]; //empty path
[arc moveToPoint:center];
CGPoint next;
next.x = center.x + radius * cos(starttime);
next.y = center.y + radius * sin(starttime);
[arc addLineToPoint:next]; //go one end of arc
[arc addArcWithCenter:center radius:radius startAngle:starttime endAngle:endtime clockwise:YES]; //add the arc
[arc addLineToPoint:center]; //back to center

[[UIColor yellowColor] set];
[arc fill];

この描画を表示するために使用されるビューの drawRect メソッドを上書きする必要があります。

于 2012-08-31T08:52:26.840 に答える
2

UIBezierPathメソッドを使用して、クラスで円弧セグメントを描画できますbezierPathWithArcCenter:radius:startAngle:endAngle:clockwiseこちらをご覧ください

の組み合わせを使用して、ラインのパスを作成する必要もあります。CGContextMoveToPoint/ CGContextAddLineToPoint

最後strokeに、パスでメソッドを呼び出して行をストロークします。

編集 内側の線を描くには、おそらくそれらをクリップしたいでしょう:これはCGContextClip関数で行われます

于 2012-08-31T08:21:44.927 に答える
0

あなたは確かに使用することができます

void CGContextAddArcToPoint

ドキュメント:

CGContext リファレンス

于 2012-08-31T08:25:55.750 に答える