How do I create an image for a UITableViewCell dynamically
- by Xetius
I want to dynamically create an image for a UITableViewCell which is basically a square with a number in it. The square has to be a colour (specified dynamically) and contains a number as text inside it.
I have looked at the CGContextRef documentation, but can't seem to work out how to get the image to fill with a specified certain colour.
This is what I have been trying so far.
-(UIImage*)createCellImageWithCount:(NSInteger)cellCount AndColour:(UIColor*)cellColour {
CGFloat height = IMAGE_HEIGHT;
CGFloat width = IMAGE_WIDTH;
UIImage* inputImage;
UIGraphicsBeginImageContext(CGSizeMake(width, height));
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
// drawing code goes here
// But I have no idea what.
UIGraphicsPopContext();
UIImage* outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outImage;
}