Ron Ron - 1 year ago 100
iOS Question

How to pass value through UIColorFromRGB in Objective-C

In this code coloring returning value =0X90EE90

coloring=[colorall objectForKey:globallinecolor];

shapeLayer.strokeColor = UIColorFromRGB(coloring).CGColor;

but this code give me error, could anyone help how could I pass the value through UIColorFromRGB.

Answer Source

You are retrieving a NSString object (coloring) but the macro expects an integer.

To get an integer from a hex string you can use NSScanner class.

Along the lines of:

unsigned int hexValue = 0;
NSScanner *scanner = [NSScanner scannerWithString:coloring];
[scanner setScanLocation:0]; // depends on your exact string format you may have to use location 1
[scanner scanHexInt:&hexValue];

shapeLayer.strokeColor = UIColorFromRGB(hexValue).CGColor;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download