HTML Content fit in UIWebview without zooming out

后端 未结 8 828
夕颜
夕颜 2020-11-27 12:21

I am making use of the UIWebView to render some HTML. However, although the width of my webview is 320 my HTML is still shown full width and can be scrolled hor

8条回答
  •  鱼传尺愫
    2020-11-27 13:08

    @implementation UIWebView (Resize)
    
    - (void)sizeViewPortToFitWidth {
        [self stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.querySelector('meta[name=\"viewport\"]').setAttribute('content', 'width=%d;', false); ", (int)self.frame.size.width]];
    }
    
    @end
    

提交回复
热议问题