2

我正在尝试绘制一个具有四个点 (A,B) (C,D) (E,F) (G,H) 的多边形,因此不一定是矩形。

然后我想在多边形上应用一个图案化的图像。

我已经研究过initWithPatternImage, colorWithPatternImage, UIBezierPathCGContextStrokeLineSegments但无法弄清楚如何将它们放在一起。

有人知道如何将它们放在一起吗?

注意:我没有使用 Open GL

4

1 回答 1

4

未经测试,但它应该像这样工作:

- (void)drawRect:(CGRect)rect
{
    UIColor *color = [UIColor colorWithPatternImage:myPatternImage];
    [color set];

    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:p1];
    [path addLineToPoint:p2];
    [path addLineToPoint:p3];
    [path addLineToPoint:p4];
    [path closePath]; // Implicitly does a line between p4 and p1
    [path fill]; // If you want it filled, or...
    [path stroke]; // ...if you want to draw the outline.
}

如果你想描边它,你可能想通过或类似的方式设置线宽[path setLineWidth:5];,并查看UIBezierPath控制线条外观的其他属性。

于 2011-05-01T11:42:37.203 回答