IOS UIWebView自适应

   //网页

    UIWebView*_webView=[[UIWebView alloc]initWithFrame:CGRectMake(0,10, screenWidth, 10)];

    _webView.delegate = self;

    _webView.scrollView.scrollEnabled = NO;

    _webView.backgroundColor=[UIColor whiteColor];

    if (![PostDic isKindOfClass:[NSNull class]]&&![PostDic[@"content"] isKindOfClass:[NSNull class]]&&PostDic[@"content"]!=nil){

        NSString *myStr = [NSString stringWithFormat:@"",screenWidth-15];

        NSString *str = [NSString stringWithFormat:@"%@%@",myStr,@"网页内容"]; [_webView loadHTMLString:str baseURL:nil];




//网页加载完成

- (void)webViewDidFinishLoad:(UIWebView *)webView

{

    NSString *htmlHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"];

    NSString *htmlWidth = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth"];

    float i = [htmlWidth floatValue]/[htmlHeight floatValue];

    int height = (screenWidth)/i;

    _webView.frame = CGRectMake(0, _titleTextF.bottom+10, screenWidth, height);

}


你可能感兴趣的:(UIWebView)