2012-03-30 158 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