我需要用drawRect()方法填充UIView中的'还原多边形' - 视图中的所有内容都用除多边形之外的某种颜色填充。UIView drawRect():填充除多边形以外的所有东西
我有了这个代码,以绘制一个简单多边形:
CGContextBeginPath(context);
for(int i = 0; i < corners.count; ++i)
{
CGPoint cur = [self cornerAt:i], next = [self cornerAt:(i + 1) % corners.count];
if(i == 0)
CGContextMoveToPoint(context, cur.x, cur.y);
CGContextAddLineToPoint(context, next.x, next.y);
}
CGContextClosePath(context);
CGContextFillPath(context);
我发现了一个类似的问题,但在C#中,没有对象 - C:c# fill everything but GraphicsPath
您可以用填充颜色填充整个视图,也比使用清晰的彩色 – Sohaib
尝试同样喜欢在C#代码绘制您的多边形过它:CGContextAddRect(背景下,self.bounds)CGContextClosePath – Felix