[objective-c]RGBAで指定した色のUIImageを生成

RGBAで指定した色のUIImageを生成

-(UIImage*)get255ColorRectImage:(float)r g:(float)g b:(float)b alpha:(float)alpha size:(CGSize)_size{
    UIGraphicsBeginImageContext(_size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(context, r/255.0,g/255.0,b/255.0,alpha/255.0);
    CGContextFillRect(context, CGRectMake(0.0,0.0,_size.width,_size.height));
    UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return screenImage;
}

UIImage*redImage=[self get255ColorRectImage:255.0 g:0.0 b:0.0 alpha:255.0 size:CGSizeMake(100, 100)];