IPhone, casting a string as hex representation of an integer

Recently i have found a nice routine that convers hex color to UIColor objects to be used on UIComponents : http://cocoamatic.blogspot.com/2010/07/uicolor-macro-with-hex-values.html

but i was confronted to a little problem, the given colors are Strings and the routine only works with hex representation of integers. So this is a little trick to make the conversion :

unsigned int hexSeparatorColor;
NSScanner *scanner = [NSScanner scannerWithString:@"0xFF0000"];
[scanner scanHexInt:&hexSeparatorColor];
[scanner release];

hexSeparatorColor will contain the hex representation of the casted string !

Leave a Reply