How to set scroll position on uiwebview

后端 未结 2 1236
醉话见心
醉话见心 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];           
    

提交回复
热议问题