Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Rhalliwell1

macrumors 6502a
Original poster
May 22, 2008
588
1
I have a small UIWebView which i want to scale so it shows a sort of preview like view of the web page - a bit like the top sites view in desktop safari.

Heres my code:

Code:
UIWebView *webPage = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 120)];
NSURL *pageURL = [[NSURL alloc] initWithString:@"http://www.google.com/"];
[webPage loadRequest:[NSURLRequest requestWithURL:pageURL]];
webPage.userInteractionEnabled = NO;
webPage.scalesPageToFit = YES;

and heres the current result:



anyone know how to resolve this?

Thanks :)
 
Thanks! How would you go about doing that?

I thought you might ask that!

0) Reference for the functions I use is here
1) Create a context to render into with UIGraphicsBeginImageContext
2) Render the layer property of the view with drawInContext:.
3) Get the image out of the context with UIGraphicsGetImageFromCurrentImageContext
4) End the context with UIGraphicsEndImageContext

You now have a UIImage containing the rendered view (which does not have to be on screen). You can now do what you want with it including display it at whatever scale you want in the normal way (if you don't know this read the documentation).

I would note all of the above is discoverable if you read the documentation.
 
Thanks so much!

I knew there was something somewhere but it is knowing where to look that is the problem :)

thanks again!
 
The compiler is saying it cannot find the -drawInContext: method


Code:
UIGraphicsBeginImageContext(webPage.bounds.size);
[webPage.layer drawInContext:UIGraphicsGetCurrentContext()]; //warning here
UIImage *webPageImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();




I tried the -renderInContext: method too but got the same result.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.