سؤال

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