我正在创建一个这样的彩色图像:
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context,
[[UIColor redColor] CGColor]);
// [[UIColor colorWithRed:222./255 green:227./255 blue: 229./255 alpha:1] CGColor]) ;
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
然后将其用作按钮的背景图像:
[resultButton setBackgroundImage:img forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
使用redColor可以很好地工作,但是我想使用RGB颜色(如注释行所示).当我使用RGB颜色时,按钮背景不会改变.
我错过了什么?