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

Denvildaste

macrumors newbie
Original poster
Apr 7, 2010
8
0
Hello, I'm trying to draw a single line, the code works but the line is not the right color and is 2 pixels thick despite me explicitly telling it to use 1 pixel as line width, what's more confusing is that if I increase the line width the color changes! what am I doing wrong? here's my code:

Code:
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
CGContextSetLineWidth(ctx, 1) ;
CGContextBeginPath(ctx);
CGContextSetRGBStrokeColor(ctx, (CGFloat)255/255, (CGFloat)0/255, (CGFloat)0/255, 1.0);
CGContextMoveToPoint(ctx, 0, 450);
CGContextAddLineToPoint(ctx, 320, 450);
CGContextStrokePath(ctx);
 
Canonical form for a 8-bit color component constant, but converted to match the API.

I prefer (CGFloat)0.0/255.0 ;

I would just write (CGFloat) 0.0 personally...

Edit to add: try drawing between the pixels (seriously). I know on Mac OSX if you want a perfect one pixel line drawing at x.5 gets that. Note sure if the iPhone is the same...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.