如何动态更改webView的高度? [英] How to change the height of webView dynamically?

查看:82
本文介绍了如何动态更改webView的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用webView来显示新闻,在我打算放置一些按钮的新闻下面。所以我需要获得webView的高度,以便在下载后根据webView的高度更改按钮的位置。换句话说,如何动态更改webView的高度?

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 according to the height of webView after all are downloaded.in other words,how to change the height of webView dynamically?

推荐答案

试试这个

    - (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];
        }
    }

这篇关于如何动态更改webView的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆