NSScanner scanFloat returning unexpected results

Posted by E-Madd on Stack Overflow See other posts from Stack Overflow or by E-Madd
Published on 2010-04-16T16:59:46Z Indexed on 2010/04/16 17:13 UTC
Read the original article Hit count: 396

I'm trying to build a UIColor from a comma-delimited list of values for RGB, which is "0.45,0.53,0.65", represented here by the colorConfig object...

NSScanner *scanner = [NSScanner scannerWithString:colorConfig];
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"\n, "]];
float red, green, blue;
return [UIColor colorWithRed:[scanner scanFloat:&red] green:[scanner scanFloat:&green] blue:[scanner scanFloat:&blue] alpha:1];

But my color is always coming back as black. So I logged the values to my console and I'm seeing Red = -1.988804, Green = -1.988800, Blue = -1.988796

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone-sdk