Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

ios - UIColor colorWithRed:green:blue:alpha: always returns white unless one argument is 0

I am using

[UIColor colorWithRed:136 green:155 blue:218 alpha:1.0]; 

to change the background color of my table view cells.

But for some reason the background just stays white. If I try

[UIColor colorWithRed:0 green:155 blue:218 alpha:1.0]; 

the color changes. This does not make sense to me. Any advice or tips?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The parameter aren't a values of 0 to 255 but a float between 0.0 and 1.0:

[UIColor colorWithRed:0.0f/255.0f green:155.0f/255.0f blue:218.0f/255.0f alpha:1.0f]; 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...