webview自适应高度

来源:互联网 发布:wemall java版 编辑:程序博客网 时间:2024/05/18 03:16


    _detailWebView = [[UIWebViewalloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(view.frame)+35,KScreenWidth,KScreenHeight-64-290)];

    _detailWebView.delegate = self;

    //预先加载url

    NSString *detailStr = self.model.questiondesc;

    

    NSString *newUrll = [detailStrstringByReplacingOccurrencesOfString:@"/upimg"withString:@"http://"];

        

   [_detailWebView loadHTMLString:newUrll baseURL:nil];

    

    [self.viewaddSubview:self.detailWebView];



#pragma mark - UIWebView Delegate Methods

-(void)webViewDidFinishLoad:(UIWebView *)webView

{

    //获取到webview的高度

    CGFloat height = [[self.webViewstringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"]floatValue];

    

    self.webView.frame =CGRectMake(self.webView.frame.origin.x,self.webView.frame.origin.y,KScreenWidth, height+20);

    

}


1 0
原创粉丝点击