UIWebView — load external website, programmatically set initial zoom scale, and allow user to zoom afterwards

You can add or modify a <meta name=”viewport” tag to achieve this. Apple documentation on the meta/viewport tag here: https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html Here’s an example of adding the tag once the document is loaded: – (void) webViewDidFinishLoad:(UIWebView *)webView { NSString* js = @”var meta = document.createElement(‘meta’); ” \ “meta.setAttribute( ‘name’, ‘viewport’ ); ” \ “meta.setAttribute( ‘content’, ‘width … Read more

iPhone UIWebView width does not fit after zooming operation + UIInterfaceOrientation change

I found something that worked for me. The problem is that when uiwebview changes its orientation web contents are zoommed to fit with viewport. But zoomscale parameter of scrollview subview is not updated correctly (nor are updated minimumZoomScale nor maximumZoomScale Then we need to do it manually at willRotateToInterfaceOrientation: – (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { CGFloat ratioAspect … Read more

UIWebView – Enabling Action Sheets on tags

Yes apple has disabled this feature (among others) in UIWebViews and kept it for Safari only. However you can recreate this yourself by extending this tutorial, http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/. Once you’ve finished this tutorial you’ll want to add a few extra’s so you can actually save images (which the tutorial doesn’t cover). I added an extra notification … Read more

Correct way to load image into UIWebView from NSData object

I tested the code with PNG (“image/png”), JPG (“image/jpeg”) and GIF (“image/gif”), and it works as expected: [webView loadData:imageData MIMEType:imageMIMEType textEncodingName:nil baseURL:nil]; Now, what’s wrong with your app? the imageData is not a well-formed image data. Try opening the file with a web browser or an image editor to check it. the MIME type is … Read more

Disable links in UIWebView?

You can give the UIWebView a delegate and implement the -webView:shouldStartLoadWithRequest:navigationType: delegate method to return NO; (except on the initial load). That will prevent the user from viewing anything but that single page. To provide an example requested in the comments… Start with allowLoad=YES and then: – (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { return allowLoad; } – … Read more