UIWebView自适应内容的高度

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>


//自适应文字的高度

- (void)webViewDidFinishLoad:(UIWebView *)webView

{


    NSString *height_str= [webView stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"];

    int height = [height_str intValue];

    webView.frame = CGRectMake(0,titleLabel.frame.origin.y+titleLabel.frame.size.height+5,SCREEN_WIDTH-20,height+30);

    timeLabel.frame=CGRectMake(20, webView.frame.origin.y+webView.frame.size.height+5, SCREEN_WIDTH-10-10, 20);

    background.frame = CGRectMake(10, 20, SCREEN_WIDTH-20, timeLabel.frame.origin.y+timeLabel.frame.size.height+5);

    NSLog(@"height: %@", [webView stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"]);

}