I am trying to draw a line
my Code is this
-(void) drawRect:(CGRect) rect
{
NSLog(@"Reached Draw ARect Function");
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, 2.0);
CGContextSetRGBStrokeColor(ctx, 1.0, 2.0, 0, 1);
CGContextMoveToPoint(ctx, 0, 0);
CGContextAddLineToPoint( ctx, 100,100);
CGContextStrokePath(ctx);
}
and i am calling from the viewDidLoad as follows
- (void)viewDidLoad {
[super viewDidLoad];
CGRect k = CGRectMake(1.0, 1.0, 100.0, 200.0);
[self.view drawRect:k];
}
Can any one help me please?
You should subclass a
UIViewand move your line drawing code to thedrawRect:method, like you are doing (just hoping it’s for a UIView subclass and not the UIViewController)You must also make sure you use the UIView subclass in InterfaceBuilder for the view you will be drawing into. You should not have to call this method yourself. If you want to animate something you should call the
[view setNeedsDisplay];to request a redraw of the view.…and…you should add
CGContextBeginPath(ctx);just before you callCGContextMoveToPoint