How to change the height of webView dynamically?

前端 未结 4 1127
無奈伤痛
無奈伤痛 2021-01-16 10:22

I\'m currently using webView to display news,below the news I intend to put some buttons.so I need to get the height of webView so as to change the position of buttons accor

4条回答
  •  星月不相逢
    2021-01-16 11:03

    try this

        - (void)webViewDidFinishLoad:(UIWebView *)webView
        {
            NSString *string = [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"body\").offsetHeight;"];
            CGFloat height = [string floatValue] + 8;
            CGRect frame = [_webView frame];
            frame.size.height = height;
            [_webView setFrame:frame];
    
            if ([[self delegate] respondsToSelector:@selector(webViewController:webViewDidResize:)])
            {
                [[self delegate] webViewController:self webViewDidResize:frame.size];
            }
        }
    

提交回复
热议问题