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

后端 未结 4 1135
轻奢々
轻奢々 2020-12-03 23:23

I am using

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

to change the background color of my table view cells.

But fo

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 23:52

    The params are not integers but floats, so you probably want to divide all color float values with 255. Like this:

      [UIColor colorWithRed:136.0/255 green:155.0/255 blue:218.0/255 alpha:1.0];
    

    That's why the color changes when you set red to 0 instead of 1 which 136 means in this case.

提交回复
热议问题