开发者

Draw a polygon and fill it with a background image

I am trying to draw a polygon with four points (A,B) (C,D) (E,F) (G,H) therefore not necessarily a rectangle.

I then want to apply a patterned image on to the polygon.

I have looked into initWithPatternImage, colorWithPatternImage, 开发者_如何学GoUIBezierPath, CGContextStrokeLineSegments but can't figure out how to put it all together.

Anybody got any ideas of how you could put them all together?

NOTE: I'm not using Open GL


Not tested, but it should work like this:

- (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.
}

If you want to stroke it, you might want to set line width via [path setLineWidth:5]; or something like that and also look into the other properties of UIBezierPath that control the line appearance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜