cg not drawing

Discussion in 'iOS Programming' started by chhoda, Aug 18, 2009.

  1. chhoda macrumors 6502

    Joined:
    Oct 25, 2008
    #1
    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];
    }
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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?
     

Share This Page