I am trying to initialize UIColor
instance with whiteColor
and I am not able to do it. The screen appears black if I do this:
color = [UIColor colorWithWhite:1.0 alpha:1.0];
But below line works fine ...
color = [UIColor colorWithRed:197.0/255.0
green:169.0/255.0
blue:140.0/255.0
alpha:1.0];
I am sure I am doing something stupid, any ideas?
Suggested approach: In the old days values outside of 0 and 1 would be clamped (i.e., forced to 0 or 1) because they didn't mean anything, but wide color support means that is no longer the case – a red value beyond 1.0 is especially red, going into the Display P3 gamut.
In Objective-C, we use this code to set RGB color codes for views: #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] view.
alpha. The opacity value of the new color object, specified as a value from 0.0 to 1.0.
UIColor *color = [UIColor whiteColor];
Your code color = [UIColor colorWithWhite:1.0 alpha:1.0]
should work just fine. Could it be that you forgot a semicolon in the end?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With