2011-08-02 13 views
1

私は以下を持っていますが、それは円の境界線を描くだけです。 サークルを記入したいと思います。 ??サークル(CGContextAddArc)を別の色で塗りつぶすにはどうすればいいですか?

CGContextRef context = UIGraphicsGetCurrentContext(); 

CGContextAddArc(context, 50, 50, 50, 0, 30, 0); 

//set the fill or stroke color 
CGContextSetRGBFillColor(context, 1, 0.5, 0.5, 1.0); 
CGContextSetRGBStrokeColor(context, 0.5, 1, 0.5, 1.0); 

//fill or draw the path 
CGContextDrawPath(context, kCGPathStroke); 
CGContextDrawPath(context, kCGPathFill); 

答えて

2

あなたは、パスを埋めるためにCGContextFillPathを使用する必要があります。

1

ストロークに関連する行を削除し、行に関連する行のみを使用します。

CGContextRef context = UIGraphicsGetCurrentContext(); 

CGContextAddArc(context, 50, 50, 50, 0, 30, 0); 

//set the fill or stroke color 
CGContextSetRGBFillColor(context, 1, 0.5, 0.5, 1.0); 

//fill or draw the path 
CGContextDrawPath(context, kCGPathStroke); 

あなたはソリッドカラーを充填するための唯一の円

CGContextRef context = UIGraphicsGetCurrentContext(); 

CGContextAddArc(context, 50, 50, 50, 0, 30, 0); 

CGContextSetRGBStrokeColor(context, 0.5, 1, 0.5, 1.0); 
CGContextDrawPath(context, kCGPathStroke); 
1

をしたい場合は、それはそれはkCGPathStrokeような何か

CGContextDrawPath(context, kCGPathStroke);にする必要があります色付きストロークの場合は CGContextDrawPath(context, kCGPathFill);

kCGPathFillを持っている必要がありますこれは:

あなたがサークルを埋めるためにしたい場合は
CGContextRef context = UIGraphicsGetCurrentContext(); 

CGContextAddArc(context, 50, 50, 50, 0, 30, 0); 

//set the fill or stroke color 
CGContextSetRGBFillColor(context, 1, 0.5, 0.5, 1.0); 

//fill on drawn path 
CGContextDrawPath(context, kCGPathFill); 
0
CGContextAddArc(ctx, x, y, 1.0, 0, 2 * Pi, 1); // Or is it 2 * M_PI? 

CGContextSetFillColorWithColor(ctx, fillColor); 
CGContextSetStrokeColorWithColor(ctx, strokeColor); 
CGContextDrawPath(ctx, kCGPathFillStroke);; 
0

あなたはこの

CGContextRef context = UIGraphicsGetCurrentContext(); 

CGContextAddArc(context, 50, 50, 50, 0, 30, 0); 

CGContextSetRGBFillColor(context, 1, 0.5, 0.5, 1.0); 

CGContextFillPath(context); 

CGContextRef context = UIGraphicsGetCurrentContext(); 

CGContextAddArc(context, 50, 50, 50, 0, 30, 0); 

CGContextSetRGBStrokeColor(context, 0.5, 1, 0.5, 1.0); 

CGContextStrokePath(context); 

ので、円の境界線を描画するために使用される以下のこのコードを使用することができますこの場合、円を埋めるために最初の選択肢を選択する必要があります

0

塗りつぶしパス:

let context = UIGraphicsGetCurrentContext() 
    CGContextAddArc(context, self.bounds.width/2, self.bounds.height/2, 150, 0, CGFloat(2 * M_PI), 0) 
    UIColor.redColor().setFill() 
    CGContextFillPath(context) 

円:

 let context = UIGraphicsGetCurrentContext() 
     CGContextAddArc(context, self.bounds.width/2, self.bounds.height/2, 150, 0, CGFloat(2 * M_PI), 0) 
     CGContextSetLineWidth(context, 10) 
     UIColor.greenColor().set() 
     CGContextStrokePath(context) 
関連する問題