Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thangiavel

macrumors newbie
Original poster
Sep 5, 2011
13
0
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);
}
 
Last edited by a moderator:

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.