Added whitespace in UIWebview - removing UIWebView whitespace in iOS7 & iOS8

前端 未结 6 2083
鱼传尺愫
鱼传尺愫 2020-12-13 18:43

Im loading local html files, since iOS7 there is added white space on top in the UIWebView.(I cant post an image as i do not have enough points.) image can be seen here- sna

6条回答
  •  不知归路
    2020-12-13 19:23

    I had the same problem so I tried a few things:-)

    This worked for me, but correct me please if there is a better way.

    -(void)webViewDidFinishLoad:(UIWebView *)webView
     {
       if(self.navigationController.navigationBar.translucent == YES)
       {
    
        _webView.scrollView.contentOffset = CGPointMake(_webView.frame.origin.x, _webView.frame.origin.y - 54);
    
       }
     }
    

    So basically you need to :

    1) Add the UIWebView delegate method - webViewDidFinishLoad: 2) Then I setup an if statement to check if the translucent option is active.

    The last one you only need to do of course if you give the user the option within your app. The number after the _webView.frame.origin.y is just for my app. It may differ for you.

提交回复
热议问题