UIWebView scaling page so that there is no need for horizontal scrolling

拈花ヽ惹草 提交于 2019-12-04 22:38:59
sergio

I think that defining the viewport for your UIWebView could help:

<meta name="viewport" content="width=device-width"/>

this is to use the full width of the device; if your UIWebView is smaller, that you can specify its width in points.

In case you need to add the meta tag to the HTML of your page after loading it, you can use this code:

- (void) webViewDidFinishLoad:(UIWebView *)webView {

  NSString* js = 
  @"var meta = document.createElement('meta'); "
   "meta.setAttribute( 'name', 'viewport' ); "
   "meta.setAttribute( 'content', 'width = device-width' ); "
   "document.getElementsByTagName('head')[0].appendChild(meta)";

  [webView stringByEvaluatingJavaScriptFromString: js];        
}

Also check this S.O. thread for another technique for the same.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!