I have two colors here is a log of the instances:
(lldb) po acolor
UIDeviceRGBColorSpace 0.929412 0.133333 0.141176 1
(lldb) po hexColor
UIDeviceRGBColorSpace 0.929412 0.133333 0.141176 1
I have this code that works for iPhone 4s 5 but not for iPhone 6:
if ([acolor isEqual:hexColor])
{
// other code here.
}
As additional I create this acolor from pixel of image:
CGFloat red = (rawData[byteIndex] * 1.0) / 255.0;
CGFloat green = (rawData[byteIndex + 1] * 1.0) / 255.0;
CGFloat blue = (rawData[byteIndex + 2] * 1.0) / 255.0;
CGFloat alpha = (rawData[byteIndex + 3] * 1.0) / 255.0;
But seems there is some differences for values between iPhone 4 and iPhone 6:
for example if I print red on iPhone 6 it has:
(lldb) po red
0.92941176470588238
and for iPhone 4:
(lldb) po red
0.929411768
The values are different because of 32 and 64 bits architecture as I think.
But as we see at colors they seems have right values and seems they rounded. but it never compare it with success. So acolor is not equal hexColor. Never. only for iPhone 4 and 5.
Of course I can use float
type instead of CGFloat
. But just noticed that rounding seems work and UIColors
has the same values for different devices. But comparing does not work.
I get hexColor using this methods:
+ (UIColor *)colorWithHexString:(NSString *)hexString
{
const char *cStr = [hexString cStringUsingEncoding:NSASCIIStringEncoding];
long x = strtol(cStr, NULL, 16);
return [UIColor colorWithHex:(UInt32)x];
}
+ (UIColor *)colorWithHex:(UInt32)col {
unsigned char r, g, b;
b = col & 0xFF;
g = (col >> 8) & 0xFF;
r = (col >> 16) & 0xFF;
return [UIColor colorWithRed:(float)r/255.0f
green:(float)g/255.0f
blue:(float)b/255.0f
alpha:1];
}