How to rotate the line drawn using CGContext.

Discussion in 'iOS Programming' started by thangiavel, Sep 5, 2011.

  1. thangiavel, Sep 5, 2011
    Last edited by a moderator: Sep 5, 2011

    thangiavel macrumors newbie

    Joined:
    Sep 5, 2011
    #1
    I used the code given below is to draw a line using CGContext...i could draw the line using cg context...but i want to know how to rotate the line drawn by cg context....i hope anyone can give me the best solution with the exact code.....
    Code:
    - (void)drawRect:(CGRect)rect
    {
    	// Draw a line
    	
    	CGContextRef context    = UIGraphicsGetCurrentContext();
    	
        CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    	
        // Draw them with a 2.0 stroke width so they are a bit more visible.
        CGContextSetLineWidth(context, 2.0);
    	
    	
        CGContextMoveToPoint(context, 0,20); //start at this point
    	
        CGContextAddLineToPoint(context, 320, 480); //draw to this point
    	
        // and now draw the Path!
        CGContextStrokePath(context);
    	 CGContextClosePath(context);
    	CGAffineTransform rotation = CGAffineTransformMakeRotation(6.283185307);
        CGContextConcatCTM(context, rotation);
    }
    
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Options:

    1) Draw the line you actually want by using different coordinates for the start and/or end points

    2) Put the transform where it will actually do something (like before the drawing)
     

Share This Page