Reputation: 1207
I input this in viewDidLoad
self.view.backgroundColor = [UIColor colorWithRed:231/255.0 green:77/255.0 blue:77/255.0 alpha:1.0];
and create label in xib , set color e74d4d(which convert to rgb is 231,77,77)
I want to show image on the website , but it tells me I need 10 reputation.
I debug the code,and find this,
(lldb) po self.view.backgroundColor
UIDeviceRGBColorSpace 0.905882 0.301961 0.301961 1
(lldb) po self.label.textColor
UIDeviceRGBColorSpace 0.87161 0.208926 0.237916 1
Upvotes: 3
Views: 1191
Reputation: 892
while you are passing value for UIColor always use float value.
self.view.backgroundColor = [UIColor colorWithRed:231.0/255.0 green:77.0/255.0 blue:77.0/255.0 alpha:1.0];
also use the same float value while you are converting to other format.
Edit: From the comments. Dividing 231/255.0 and 231.0/255.0 are the same. Yes it is, but i have written that always pass float value means in for both values.
As user doesn't provided second conversation i thought function is using 255 for devision instead of 255.0 as a result it will be a integer value.
Try below code with RGBFromUIColor macro one by one, it will show different output.
self.titleLabel.backgroundColor = [UIColor colorWithRed:231/255 green:77/255 blue:77/255 alpha:1.0];
self.titleLabel2.backgroundColor = [UIColor colorWithRed:231.0/255.0 green:77.0/255.0 blue:77.0/255.0 alpha:1.0];
self.titleLabel3.backgroundColor = RGBFromUIColor(231, 77, 77);
self.titleLabel4.backgroundColor = RGBFromUIColor(231.0, 77.0, 77.0)
Now suppose macro for RGBFromUIColor is like below
#define RGBFromUIColor(r, g, b) \[UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
or like this
#define RGBFromUIColor(r, g, b) \[UIColor colorWithRed:(r)/255 green:(g)/255 blue:(b)/255 alpha:1]
The last RGBFromUIColor will not have same value in case it doen't devided by float i.e 255.0
Upvotes: 4
Reputation: 8618
This may not be what you are experiencing, but it I have previously seen some color problems with the OS X Color Picker due to the color calibration on my display. Sometimes it seems to select the color components by display value and then convert them to sRGB, when you actually want no conversion at all.
I would try the either of the following:
Upvotes: 1
Reputation: 681
Your issue is that the text lable colour is not the same as your background colour?
I suspect your problem is that you are setting the text color to e74d4d which is a 24 bit value, no transparency value (the A in RGBA and ARGB). Try ffe74d4d or e74d4dff which set the transparency to opaque (alpha to 1). Even better, simply set it the same way as you set the background color, and iOS will automatically set the transparency to opaque.
Upvotes: 0