Note that there are some explanatory texts on larger screens.

plurals
  1. POReceiving errors when trying to draw with UIBezierPath
    text
    copied!<p>I'm trying to draw some lines inside my custom UIView.</p> <p>From what I can see, to save messing around with CoreGraphics, I can use UIBezierPath (i've done similar with NSBezierPath on the Mac). I have some code that tries to draw the lines but I get output errors and can't find a decent reference with some sample code to illustrate whats going on, any ideas? Code below...</p> <p>Code: </p> <pre><code> - (void)drawRect:(CGRect)rect { // Drawing code UIBezierPath *line1 = [UIBezierPath bezierPath]; [[UIColor blackColor] setStroke]; [line1 setLineWidth:3]; [line1 moveToPoint:CGPointMake(0, 0)]; [line1 addLineToPoint:CGPointMake(320, 480)]; [line1 stroke]; } </code></pre> <p>Errors:</p> <pre><code>Sat Oct 2 19:26:43 mercury.config mobileManual[46994] &lt;Error&gt;: CGContextSetStrokeColorWithColor: invalid context 0x0 </code></pre> <p>UPDATE: Here's the current code, No errors but also no drawing.. ideas?</p> <pre><code>// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; [self.view setBackgroundColor:[UIColor yellowColor]]; [self.view setNeedsDisplay]; } - (void)drawRect:(CGRect)rect { // Drawing code CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); UIBezierPath *line1 = [UIBezierPath bezierPath]; [line1 setLineWidth:3]; [line1 moveToPoint:CGPointMake(0, 0)]; [line1 addLineToPoint:CGPointMake(320, 480)]; [line1 stroke]; CGContextRestoreGState(context); } </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