Meg*_*anX 1 iphone core-graphics ellipse draw clip
我画了椭圆:
CGContextFillEllipseInRect(contextRef, CGRectMake(50, 50, 50, 128));
Run Code Online (Sandbox Code Playgroud)
但我只需要一半的椭圆,有没有办法夹住另一半?
在调用绘图方法之前,您可以将上下文剪切到椭圆的一部分:
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
912 次 |
| 最近记录: |