Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One approach is, </p> <p>set the background color of label to clear color, and draw the required shape inside your drawRect method using CGContext.</p> <p>Your drawRect will become like this</p> <pre><code>- (void)drawRect:(CGRect)rect{ [super drawRect:rect]; CGContextRef context = UIGraphicsGetCurrentContext(); CGRect labelRect = self.bounds; CGPoint bottomPoint = CGPointMake(labelRect.size.width, rect.size.height); CGPoint topMinus30Point =CGPointMake(labelRect.size.width-30, 0); //from bottom to -30 top CGContextMoveToPoint(context, self.bounds.origin.x,self.bounds.origin.y); CGContextAddLineToPoint(context, topMinus30Point.x,topMinus30Point.y); CGContextAddLineToPoint(context, bottomPoint.x,bottomPoint.y); CGContextAddLineToPoint(context, self.bounds.origin.x,self.bounds.origin.x + self.bounds.size.height); CGContextAddLineToPoint(context, self.bounds.origin.x,self.bounds.origin.y); CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor); CGContextFillPath(context); } </code></pre> <p>Another approach is using the <code>CGContextClip</code> using this approach your drawRect will become like this</p> <pre><code>CGContextMoveToPoint(context, self.bounds.origin.x,self.bounds.origin.y); CGContextAddLineToPoint(context, topMinus30Point.x,topMinus30Point.y); CGContextAddLineToPoint(context, bottomPoint.x,bottomPoint.y); CGContextAddLineToPoint(context, self.bounds.origin.x,self.bounds.origin.x + self.bounds.size.height); CGContextAddLineToPoint(context, self.bounds.origin.x,self.bounds.origin.y); CGContextClip(context); CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor); CGContextFillRect(context, self.bounds); </code></pre> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload