質問

I've been trying to clip my view to make it pointed on the right, but for some reason, it's not working.

The following is my code in drawRect:

CGContextRef ctx = UIGraphicsGetCurrentContext();

CGContextMoveToPoint(ctx, width - 20.0, 0.0);
CGContextAddLineToPoint(ctx, width, height / 2.0);
CGContextAddLineToPoint(ctx, width - 20.0, height);

[[UIColor blackColor] setStroke];
CGContextStrokePath(ctx);

CGContextClip(ctx);

I just put the stroke path to see if it's working. Strokes are working fine, but CGContextClip() just won't work (without the stroke function) to save my life.

Please help me!! Thanks in advance!

役に立ちましたか?

解決

Make a triangle using CoreGraphics

-(void) drawRect:(CGRect)rect {
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextMoveToPoint(ctx, CGRectGetMinX(rect), CGRectGetMinY(rect));
    CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect)/2, CGRectGetMaxY(rect));
    CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect), CGRectGetMinY(rect));
    [[UIColor redColor] setFill];
    CGContextFillPath(ctx);
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top