Hello, I'm trying to draw some lines inside my custom UIView.
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...
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];
}
Errors:
Sat Oct 2 19:26:43 mercury.config mobileManual[46994] <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0
UPDATE: Here's the current code, No errors but also no drawing.. ideas?
// 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);
}