You must do this by pointing the drawing view layer into a custom graphics context, and then creating a CGImage bitmap from that context. When you have a CGImage, you can create a UIImage from it. It would look something like this:
// Create a bitmap context. CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef bitmapContextForCell = CGBitmapContextCreate(nil, cell.bounds.size.width, cell.bounds.size.height, 8, 0, colorSpace, kCGImageAlphaNone); CGColorSpaceRelease(colorSpace); // Draw the cell layer into the context. [cell.layer renderInContext:bitmapContextForCell]; // Create a CGImage from the context. CGImageRef cgImageForCell = CGBitmapContextCreateImage(bitmapContextForCell); // Create a UIImage from the CGImage. UIImage * cellImage = [UIImage imageWithCGImage:cgImageForCell]; // Clean up. CGImageRelease(cgImageForCell); CGContextRelease(bitmapContextForCell);
How to create an image for each cell. If you want to create a single image for all your cells, use a table instead of a cell.
Ryan
source share