Reputation: 2303
I have a UIWebView that is loading content from a URL - and I'd like to display a small version, almost like a button, of that UIWebView in another view controller.
I can grab the UIWebView from its controller. How can I make its content display in a different view controller?
Upvotes: 0
Views: 279
Reputation: 33592
A view can only have one superview; that means you can't really make it render twice.
The easiest way to do what you're asking is to render it to an image and that display that image elsewhere:
#include <QuartzCore/CALayer.h>
...
UIGraphicsBeginImageContext(webview.frame.size);
[webview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Caveats:
UIGraphicsBeginImageContextWithOptions()
for "retina" support. The number of hoops you need to jump through to support both 3.x/4.x and 4.x-only builds is a bit of a pain.Upvotes: 2