I would like to draw a triangle using CGRect instead of UIImageView and add it as subview to the right corner of some particular table cells similar to how it's done on the WWDC app.
Any advice is welcomed. :)
An easy way can be to have different UIImageView's containing a colored-triangle, then selecting the different image to display according to certain values/preference that you setup. Taken from here:Drawing a triangle in UIView
You will need to do some math to calculate the correct points, but this is the general way of drawing a triangle. You can just create your own subclass of UIView (call it CornerTriangle) and then add it to the cell while settings its color to match your needs.
-(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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With