How do I create an image for a UITableViewCell dynamically
Posted
by Xetius
on Stack Overflow
See other posts from Stack Overflow
or by Xetius
Published on 2010-05-27T21:06:44Z
Indexed on
2010/05/27
22:11 UTC
Read the original article
Hit count: 223
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;
}
© Stack Overflow or respective owner