Note that there are some explanatory texts on larger screens.

plurals
  1. POCGContextEOFillPath + CGContextDrawLinearGradient
    text
    copied!<p>I have succeeded in drawing a rectangle which has a hole inside of the shape of a rounded rectangle using CGContextEOFillPath. I can change the colour of my shape. However, I would like to use a gradient, I suppose that I have got to use CGContextDrawLinearGradient, however, I can't make it work. It keep painting the entire rectangle, hole included. </p> <p>Here is the code that I am using</p> <pre><code>- (void)drawRect:(CGRect)rect { [super drawRect:rect]; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CGFloat frameWidth = 1; //[CQMFloatingContentOverlayView frameWidth]; CGFloat radius = [self cornerRadius]; CGSize viewSize = [self frame].size; CGPathRef path = CQMPathCreateRoundingRect(CGRectMake(frameWidth, frameWidth, viewSize.width - frameWidth * 2, viewSize.height - frameWidth * 2), radius, radius, radius, radius); CGContextAddRect(context, CGRectMake(0, 0, viewSize.width, viewSize.height)); CGContextAddPath(context, path); CGContextEOFillPath(context); CGPathRelease(path); CGContextRestoreGState(context); } CGPathRef CQMPathCreateRoundingRect(CGRect rect, CGFloat blRadius, CGFloat brRadius, CGFloat trRadius, CGFloat tlRadius) { CGPoint tlPoint = rect.origin; CGPoint brPoint = CGPointMake(rect.origin.x + rect.size.width, rect.origin.y + rect.size.height); CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, tlPoint.x + tlRadius, tlPoint.y); CGPathAddArcToPoint(path, NULL, brPoint.x, tlPoint.y, brPoint.x, tlPoint.y + trRadius, trRadius); CGPathAddArcToPoint(path, NULL, brPoint.x, brPoint.y, brPoint.x - brRadius, brPoint.y, brRadius); CGPathAddArcToPoint(path, NULL, tlPoint.x, brPoint.y, tlPoint.x, brPoint.y - blRadius, blRadius); CGPathAddArcToPoint(path, NULL, tlPoint.x, tlPoint.y, tlPoint.x + tlRadius, tlPoint.y, tlRadius); CGPathCloseSubpath(path); return path; } </code></pre> <p>I don't know where to put the gradient code, I have tried before and after the CGContextEOFillPath but could not reach my objective. </p>
 

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