UIColor在设置为蓝色时始终显示为白色。

3
我正在尝试使用以下代码设置UIImageView的背景颜色(应该返回一种绿色):

 cell.background.backgroundColor = [UIColor colorWithRed:50 green:200 blue:50 alpha:1];

但出于某种原因,这只会给我一个白色,似乎每当我设置蓝色时它就会变回白色,当我这样做时,它会返回黄色,这是正常的:

cell.background.backgroundColor = [UIColor colorWithRed:50 green:200 blue:0 alpha:1];
1个回答

14

好的,我之前没有意识到UIColor需要使用0-1之间的浮点数,而不是0-255,这样可以解决问题:

cell.background.backgroundColor = [UIColor colorWithRed:240.0f/255.0f green:245.0f/255.0f blue:254.0f/255.0f alpha:1];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接