Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering UIView with its children

Tags:

I have a UIView that has an image and some buttons as its subviews. I'd like to get a "snapshot" image of it using renderInContext, or other method.

[clefView.layer renderInContext:mainViewContentContext]; 

If I pass it my UIView (as above) then I get a blank bitmap. None of the children are rendered into the bitmap.

If I pass it the child view that is the image, then I get an image of that bitmap, and, unsurprisingly, none of its siblings (buttons).

I was sort of hoping that renderInContext would take the image and all it's visible children and render it into a bitmap. Has anyone have any ideas how to do this?

like image 332
mahboudz Avatar asked Apr 25 '09 10:04

mahboudz


1 Answers

Try something like this:

UIGraphicsBeginImageContext(clefView.bounds.size); [clefView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 
like image 86
rincewind Avatar answered Oct 03 '22 20:10

rincewind