2012-03-30 18 views
6

Core Graphicsを使用して半円形を描き、色を塗りつぶします.CALayerを使用して色をimageに置き換えます。誰もがこれを行う方法を助けることができますありがとう!CoreGraphicsを使用して半円を描くにはどうすればいいですか?

コードはここにあります。

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetLineWidth(context, 2); 
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
CGContextMoveToPoint(context, 0, 500); 
CGContextAddArc(context, 60, 500, 50, 90, 180, 0); 
CGContextStrokePath(context); 
+1

このリンクはあなたを助けることがあります。http://stackoverflow.com/questions/3729690/draw-part-また、以下をチェックしてください:http://stackoverflow.com/questions/2835448/how-to-draw-a-rounded-rectangle-in-core-graphics-quartz-2d – Devang

答えて

7

角度はradiansで指定する必要があります。 180度=πラジアン。あなたの例ではそう:アークが始まることがありますので、私はまた、出発点(... MoveToPoint)右に10個のピクセル移動

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetLineWidth(context, 2); 
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
CGContextMoveToPoint(context, 10, 500); 
CGContextAddArc(context, 60, 500, 50, M_PI/2, M_PI, 0); 
CGContextStrokePath(context); 

注意。

-2

先日見つけた必要なものは、Core Graphicsのコードをグラフィックスプログラムで描画した後に視覚化できる素晴らしいツールです。

これは、ペイントコードと呼ばれます。

PaintCode

+0

カスタム作成にPiantcodeを使用することはできますかコントロール。 私は、実行時に変更したい円の中央に塗りつぶした円弧を描画したいとします。効果的に新しい並べ替えのコントロール。 PaintCodeでこれを行うことはできますか?彼らのウェブサイトを見ることであまり明らかではない? – OneGuyInDc

+0

インストール(デモ)し、参照してください。知りません。 – bandejapaisa

5

与えられた答えは私のためのiOS 7に取り組んでいません!
私はパーセンテージの角度で円を作成するために小さなカテゴリを作成しました。 あなたはそれをチェックしたいと思うかもしれません。
半円だけを作成したい場合でも、methodeを採用することはできます。ここ
は次のとおりです。GitHub Link
そして、それはのようなその表情ものです:

persentage circle

+0

素晴らしい仕事!!! ... –

+0

結果にテキストが表示されていません。私はあなたがイメージの文脈にテキストを追加していないと思った、そう? –

0
CGPoint circleCenter = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); 

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetLineWidth(context, 2); 
CGContextMoveToPoint(context, circleCenter.x, circleCenter.y); 


CGContextAddArc(context, circleCenter.x, circleCenter.y, 50, 90, 180, 0); 
CGContextAddLineToPoint(context, circleCenter.x, circleCenter.y); 
CGContextSetFillColorWithColor(context, [UIColor colorWithPatternImage:[UIImage imageNamed:@"add-icon.png"]].CGColor); 
CGContextFillPath(context); 

CGContextAddArc(context, circleCenter.x, circleCenter.y, 50, 180, 90, 0); 
CGContextAddLineToPoint(context, circleCenter.x, circleCenter.y); 
CGContextSetFillColorWithColor(context, [UIColor colorWithPatternImage:[UIImage imageNamed:@"appIcon_58.png"]].CGColor); 
CGContextFillPath(context); 
関連する問題