AppyMike
AppyMike

Reputation: 2064

Take a screenshot of a UIPickerView

I use the following code to take a screenshot of my view:

UIGraphicsBeginImageContextWithOptions(containerView.bounds.size, NO, [[UIScreen mainScreen] scale]);
[toController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

It works perfectly for most cases, but produces the below image when a view contains a UIPickerView

image that is produced

And this is the image that I would like to produce.

the desired image

What's going on and how can I solve this, any ideas??

Thanks all!

EDIT: Just to note this occurs on both the device and the simulator

Upvotes: 2

Views: 187

Answers (1)

AppyMike
AppyMike

Reputation: 2064

I solved the problem by using drawViewHierarchyInRect:

UIGraphicsBeginImageContextWithOptions(containerView.bounds.size, NO, [[UIScreen mainScreen] scale]);
[toController.view drawViewHierarchyInRect:containerView.bounds afterScreenUpdates:YES];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Upvotes: 1

Related Questions