ios - UIWebView content how to resize/scale it? -
i came point able lock horizontal scroll wanted when rotate landscape portrait content still large. need resize/scale down myself don't know how far use :
- (void)viewdidload { [super viewdidload]; nsstring *fullurl = @"http://igo.nl"; nsurl *url = [nsurl urlwithstring:fullurl]; nsurlrequest *requestobj = [nsurlrequest requestwithurl:url]; [_webview loadrequest:requestobj]; _webview.scrollview.bounces = false; _webview.scalespagetofit = yes; _webview.contentmode = uiviewcontentmodescaleaspectfit; } - (void)didrotatefrominterfaceorientation:(uiinterfaceorientation)frominterfaceorientation { if(frominterfaceorientation == uiinterfaceorientationportrait) { //_webview.scrollview.contentsize = cgsizemake(320, _webview.scrollview.contentsize.height); } else { //[_webview reload]; _webview.bounds = cgrectmake(0, 0, 320,_webview.bounds.size.height); _webview.frame = cgrectmake(0, 0, 320, _webview.frame.size.height); _webview.scrollview.contentsize = cgsizemake(320, _webview.scrollview.contentsize.height); } }
edit: seem need content zoomed out
use delegate methods of uiwebviewdelegate
@interface your_class : parent_class <uiwebviewdelegate>
in viewdidload
... [_webview setdelegate:self]; ...
call delegate method
- (void)webviewdidfinishload:(uiwebview *)webview { [webview.scrollview setcontentsize: cgsizemake(webview.frame.size.width, webview.scrollview.contentsize.height)]; } - (void)willrotatetointerfaceorientation:(uiinterfaceorientation)tointerfaceorientation duration:(nstimeinterval)duration { [_webview reload]; //or use meta tag [_webview.scrollview setcontentsize: cgsizemake([_webview.scrollview.contentsize.width, _webview.scrollview.contentsize.height)]; }
you have add meta
tag html
file
<meta name="viewport" content="width=device-width" />
or reload webview
[_webview reload];
Comments
Post a Comment