You'll need an enclosing view, because UIImageView isn't intended to have subviews. Put everything you want to capture inside that enclosing view (a simple UIView will do). The following is a very simple implementation that ignores things like view transformations:
// Helper function, calls drawRect: recursively
void drawViewAndSubviews (UIView* view) {
[view drawRect:view.bounds];
CGContextRef ctx = UIGraphicsGetCurrentContext();
for (UIView* subview in view.subviews) {
CGPoint origin = subview.frame.origin;
CGContextTranslateCTM(ctx, origin.x, origin.y);
drawViewAndSubviews(subview);
CGContextTranslateCTM(ctx, -origin.x, -origin.y);
}
}
- (void)takeScreenshot:(UIView *)view {
UIGraphicsBeginImageContext(view.bounds.size);
drawViewAndSubviews(view);
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Now 'image' has a snapshot of 'view' and its subviews
}