How to change the height of webView dynamically?

前端 未结 4 1165
無奈伤痛
無奈伤痛 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:00

    Do this inside the delegate method webViewDidFinishLoad:

    - (void)webViewDidFinishLoad:(UIWebView *)aWebView
    {
        CGFloat height = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue];
        CGFloat width = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
        aWebView.frame = CGRectMake(aWebView.frame.origin.x,aWebView.frame.origin.y,width, height);
    }
    

提交回复
热议问题