Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize UIColor with white color

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?

like image 412
Rakesh Singh Avatar asked Dec 12 '11 10:12

Rakesh Singh


People also ask

What happens when color or UIColor has values outside 0 1?

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.

How do I change the RGB color in Swift?

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.

What is Alpha in UIColor?

alpha. The opacity value of the new color object, specified as a value from 0.0 to 1.0.


2 Answers

UIColor *color = [UIColor whiteColor];
like image 189
Fran Sevillano Avatar answered Sep 28 '22 03:09

Fran Sevillano


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?

like image 25
phi Avatar answered Sep 28 '22 02:09

phi