1
 UIScrollView *ScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,600)];
 ScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth ;
 ScrollView.autoresizesSubviews = YES;

[ScrollView setContentSize:CGSizeMake(320, 2500)];

ScrollView.scrollEnabled = YES;

ScrollView.directionalLockEnabled = YES;

ScrollView.showsVerticalScrollIndicator = NO;

ScrollView.showsHorizontalScrollIndicator = NO;

ScrollView.autoresizesSubviews = YES;
ScrollView.backgroundColor=[UIColor whiteColor];
[self.view addSubview:ScrollView];

  UIwebview *webView = [[UIWebView alloc]initWithFrame:CGRectMake(10,30,310,1500)];
        webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight) ;
        webView.autoresizesSubviews = YES;

        NSLog(@"vlaue od v is %@",webView);

        webView.scrollView.scrollEnabled = NO;
        webView.scrollView.bounces = NO;

        //make the background transparent
        [webView setBackgroundColor:[UIColor clearColor]];

        //pass the string to the webview

        [webView loadHTMLString:[html description] baseURL:nil];
        NSLog(@"web view is %f",webView.scrollView.contentSize.width);
        [webView sizeThatFits:CGSizeZero];
        NSLog(@"web view is %@",webView);

        //add it to the subview
        NSLog(@"height: %d", [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] intValue]);

    // CGFloat contentHeight = webView.scrollView.contentSize.height;
    //  ScrollView.contentSize = webView.scrollView.contentSize.frame.size;
   //     NSLog(@"scroll size is %d",ScrollView.contentSize);

     //   [UIScrollView setNeedsDisplay];

        [ScrollView addSubview:webView];

      NSLog(@"size is %f",ScrollView.contentSize.height);

私はこの分野の初心者です。これらすべてを適用しました。スクロール ビューに webview データを追加した後、2500 の高さを定義したようにスクロール ビューのコンテンツの長さを求め、次に 1000,1500 をカバーする量を求めます。

4

2 に答える 2

2

次の方法を使用してスクロールビューの高さを見つけることができます

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    int contentHeight = myWebView.scrollView.contentSize.height;
  Nslog(@"%d",contentHeight);
}
于 2013-06-04T08:26:55.957 に答える