How to set scroll position on uiwebview

后端 未结 2 1223
醉话见心
醉话见心 2020-12-30 04:14

I want to go to specify line on my uiwebview loaded. I tried

[webView stringByEvaluatingJavaScriptFromString:@\"window.scrollTo(0.0, 100.0)\"];

相关标签:
2条回答
  • 2020-12-30 04:44

    Make sure you set the view controller where you have your web view to be a UIWebViewDelegate, and declare this in the @interface of the header file (.h).

    [yourWebView setDelegate:self];
    



    Then, in the webViewDidFinishLoad: method, insert this code:

    [yourWebView.scrollView scrollRectToVisible:CGRectMake(0, yourWebView.bounds.size.height + 100, 1, 1) animated:NO];           
    
    0 讨论(0)
  • 2020-12-30 05:09

    Try

    webview.scrollView.contentOffset = CGPointMake(0, 100);
    
    0 讨论(0)
提交回复
热议问题