tags:

views:

36

answers:

1

Hi guys,

I want to get the layer of UIWebView then I want to render it. This is my code:

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 700, 1024)];
[webView loadHTMLString:@"Display This HTML String" baseURL:nil];

CALayer *webViewLayer = [webView layer];
[webViewLayer renderInContext:ctx];

All I am getting is blank page.

but if I take UIView instead of UIWebView then code works fine. Am I doing something wrong which I am not able to notice or cant we get the layer of UIWebView or is there any other method for getting the layer of UIWebView.

Thanx.

A: 

The UIWebView is pretty monolithic and its components are generally not intended to be accessed. Everything is more or less hidden away.

You can "cheat" by looping though the web view's subviews, but you'll probably run into Apple's disapproval of accessing private classes, e.g.:

CALayer *webViewLayer;
for (UIView *_subview in [[[webView subviews] objectAtIndex:0] subviews]) {
    if ([_subview isKindOfClass:[UIWebDocumentView class]]) {
        webViewLayer = [_subview layer];
    }
}
[webViewLayer renderInContext:ctx];

Accessing private classes will cause your app to be rejected, if you intend to publish this on the App Store.

Alex Reynolds