Draw a triangle as a subpoint in the right corner of the table cell

I would like to draw a triangle using CGRect instead of UIImageView , and add it as a subview to the right corner of some specific table cells, similar to how it is done in the WWDC application.

Any advice is appreciated. :)

WWDC App Screenshot

+4
source share
2 answers

A simple way could be to use another UIImageView containing a colored triangle, and then select another image to display according to certain settings / settings. Taken from here: Drawing a triangle in a UIView

, . UIView ( CornerTriangle), , .

-(void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGContextBeginPath(ctx);
    CGContextMoveToPoint   (ctx, CGRectGetMinX(rect), CGRectGetMinY(rect));  // top left
    CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect), CGRectGetMidY(rect));  // mid right
    CGContextAddLineToPoint(ctx, CGRectGetMinX(rect), CGRectGetMaxY(rect));  // bottom left
    CGContextClosePath(ctx);

    CGContextSetRGBFillColor(ctx, 1, 1, 0, 1);
    CGContextFillPath(ctx);
}
+8

UiTableviewCell. , :

-(void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGContextBeginPath(ctx);
    CGContextMoveToPoint   (ctx, CGRectGetMaxX(rect), CGRectGetMidY(rect));  
    CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect), CGRectGetMinY(rect));  
    CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect)-25, CGRectGetMinY(rect));  
    CGContextClosePath(ctx);

    CGContextSetRGBFillColor(ctx, 1, 1, 0, 1);
    CGContextFillPath(ctx);
}
0

All Articles