Question

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!

Was it helpful?

Solution

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top