我需要用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