2012-03-30 140 views
6

在UIView中绘制一个填充(!)半圆的最佳方法是什么?我玩过CGContextAddArc函数,但似乎没有提供填充。这是我喜欢画的 - 两个半圆。绘制一个填充的半圆

enter image description here

回答

15
CGContextBeginPath(gc); 
CGContextAddArc(gc, 100, 100, 50, -M_PI_2, M_PI_2, 1); 
CGContextClosePath(gc); // could be omitted 
CGContextSetFillColorWithColor(gc, [UIColor cyanColor].CGColor); 
CGContextFillPath(gc); 
+0

我不得不用 “CGContextSetFillColorWithColor” 功能,而不是 “CGContextSetFillColor” 的。有了它,它效果很好。谢谢! – Bernd 2012-03-30 22:35:26

+0

糟糕。固定。别客气。 – 2012-03-30 23:10:56

+0

用'CGContextRef gc = UIGraphicsGetCurrentContext();定义cg以使其工作 – josef 2013-11-13 23:18:25