在设置颜色时用[UIColor colorWithRed: green: blue: alpha:] , 代码写好后,运行起来可能没有任何效果,比如:
self.backgroundColor = [UIColor colorWithRed:85.0 green:198.0 blue:240.0 alpha:1.0];
但是直接使用系统提供的颜色,又能正常显示:
self.backgroundColor = [UIColor grayColor];
所以问题应该出在 "colorWithRed" 这个方法的使用上,要么是方法使用错误,要么是参数错误
经过分析,发现了问题的所在:RGB的颜色值范围都是在0.0~1.0之间的,并不是我们误认为的0~255,修改如下:
self.backgroundColor = [UIColor colorWithRed:85.0 / 255.0 green:198.0 / 255.0 blue:240.0 / 255.0 alpha:1.0];
[UIColor colorWithRed: green: blue: alpha:]接口,apple文档解释如下: