PDA

View Full Version : cg not drawing




chhoda
Aug 18, 2009, 03:12 PM
I am tryin to draw an indicator in a scrollview. i am trying with following code. It is not drawing anything at all. What could be the problem ?

- (void) drawScrollIndicator {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 10.0);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 0, self.frame.origin.y / 2);
CGContextStrokePath(context);
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[self drawScrollIndicator];
}



PhoneyDeveloper
Aug 18, 2009, 03:39 PM
Two things come to mind.

You can't draw in a view except in response to a drawRect call. Implement drawRect for your view and call setNeedsDisplay as required to make your drawRect method be called.

What is the value of self.frame.origin.y / 2?

Are you aware that scroll views can already draw scroll indicators?