Reputation: 2064
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
And this is the image that I would like to produce.
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
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