ios - How to size UIWebView in a UIModalPresentationFormSheet? -
i tried every permutation known mankind , cannot uiwebview size in modal form view ipad. web page still displays full ipad portrait width of 768 points.
where , how tell uiwebview display width 540 points?
i thought 'scalespagetofit' supposed not work.
i tried setting web view size of form view 540 x 576 navigation , status bar. height irrelevant though.
i tried adding uiwebview uiview in storyboard resizing set. removed uiwebview , added programmatically.
- (void)viewdidload { [super viewdidload]; cgrect aframe = self.view.frame; if (is_ipad) { aframe = cgrectmake(0, 0, form_view_width, form_view_height); } _webview = [[uiwebview alloc] initwithframe:aframe]; [_webview setopaque:no]; [_webview setdelegate:self]; [_webview setscalespagetofit:yes]; self.view = _webview; ... }
i tried loading in viewdidappear (in addition viewdidload, viewwillappear, etc.)
- (void)viewdidappear:(bool)animated { [super viewdidappear:animated]; [[self webview] setframe:cgrectmake(0, 0, form_view_width, form_view_height)]; [[self webview] setscalespagetofit:yes]; nsurl *weburl = [nsurl urlwithstring:@"http://www.google.com"]; nsurlrequest *request = [nsurlrequest requestwithurl:weburl cachepolicy:nsurlrequestuseprotocolcachepolicy timeoutinterval:5.0f]; [[self webview] loadrequest:request]; }
any recommendations appreciated.
this keeps happening me. post lengthy question, 2 seconds later find answer.
anyway, posted solution problem here: uiwebview -- load external website, programmatically set initial zoom scale, , allow user zoom afterwards
however, altered script set width ipad width:
- (void)webviewdidfinishload:(uiwebview *)webview { nsstring* js = @"var meta = document.createelement('meta'); " @"meta.setattribute( 'name', 'viewport' ); " @"meta.setattribute( 'content', 'width = 540px, initial-scale = 1.0, user-scalable = yes' ); " @"document.getelementsbytagname('head')[0].appendchild(meta)"; [[self webview] stringbyevaluatingjavascriptfromstring: js]; }
note portion 'width = 540px, initial-scale = 1.0, user-scalable = yes'
i changed width form width , scale 1.0.
i need handle iphone, , make adjustments next. think fix may needed ipad form view.
update: answer short-lived. if load other page sizing thrown off again. square one.
solution: view need access few web pages developed. therefore, updated few web pages need access adding meta tag each of them. need access these pages , solution plan go with. means need set viewport width 540px ipad somehow. figure out next.
<meta name="viewport" content="width:540, initial-scale=1, maximum-scale=1">
Comments
Post a Comment