1

私は楕円を描きました:

CGContextFillEllipseInRect(contextRef, CGRectMake(50, 50, 50, 128));

しかし、楕円の半分だけが必要です。残りの半分を切り取る方法はありますか?

4

1 に答える 1

5

描画メソッドを呼び出す前に、コンテキストを楕円の一部にクリップできます。

CGContextSaveGState(contextRef);
BOOL onlyDrawTopHalf = YES;
CGFloat halfMultiplier = onlyDrawTopHalf ? -1.0 : 1.0;
CGRect ellipse = CGRectMake(50, 50, 50, 128);
CGRect clipRect = CGRectOffset(ellipse, 0, halfMultiplier * ellipse.size.height / 2);
CGContextClipToRect(contextRef, clipRect);
CGContextFillEllipseInRect(contextRef, ellipse);
// restore the context: removes the clipping
CGContextRestoreGState(contextRef);
于 2011-12-09T17:23:14.120 に答える