Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use the following method from <a href="http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIBezierPath_class/Reference/Reference.html#//apple_ref/occ/cl/UIBezierPath" rel="nofollow"><code>UIBezierPath</code></a>:</p> <pre><code>+ (UIBezierPath *)bezierPathWithCGPath:(CGPathRef)CGPath </code></pre> <p>The reuse of a <code>CGPath</code> is valid. Check this example adding <code>TestView</code> in a <code>UIViewController</code> and linking a <code>UIButton</code> to force the redraw when clicking on it with <code>[_testView setNeedsDisplay]</code>:</p> <pre><code>// TestView.h #import &lt;UIKit/UIKit.h&gt; @interface TestView : UIView { CGMutablePathRef _path; BOOL _nextDraws; } @end // TestView.m #import "TestView.h" @implementation TestView - (void)drawRect:(CGRect)rect { BOOL firstDraw = !_nextDraws; CGContextRef ctx = UIGraphicsGetCurrentContext(); if (firstDraw) { NSLog(@"first draw"); _path = CGPathCreateMutable(); CGPathMoveToPoint(_path, NULL, 0, 0); CGPathAddLineToPoint(_path, NULL, CGRectGetMaxX(rect), CGRectGetMaxY(rect)); CGPathCloseSubpath(_path); CGContextAddPath(ctx, _path); CGContextSetStrokeColorWithColor(ctx,[UIColor whiteColor].CGColor); CGContextStrokePath(ctx); _nextDraws = YES; } else { NSLog(@"next draws"); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextClearRect(ctx, rect); UIBezierPath * bezierPath = [UIBezierPath bezierPathWithCGPath:_path]; CGContextAddPath(ctx, bezierPath.CGPath); CGContextSetStrokeColorWithColor(ctx,[UIColor whiteColor].CGColor); CGContextStrokePath(ctx); } } - (void)dealloc { CGPathRelease(_path); [super dealloc]; } @end </code></pre>
 

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