Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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- snap shot from iPhone simulator, uiwebview surrounded by black frame, the html content is grey, but there is white added above it

I have tried to adjust the zoom using

[webView stringByEvaluatingJavaScriptFromString:@"document. body.style.zoom = 5.0;"];
webView.scalesPageToFit = NO;
  • credit to: Srikar Appal

I also set tried to remove white spacing:

 NSString *padding = @"document.body.style.margin='0';document.body.style.padding = '0'";
[webView stringByEvaluatingJavaScriptFromString:padding];
  • credit to: thenextmillionaire

still no luck. In the desktop chrome browser there is no whitespace. The html files are Google Swiffy files - containing html and JSON.

edit: updated Image

like image 238
DevC Avatar asked Sep 22 '13 19:09

DevC


2 Answers

Try self.automaticallyAdjustsScrollViewInsets = NO; in ViewDidLoad.

ios 7 add 64px automatically for scroll view. (status bar and nav bar)

like image 85
Yiding Avatar answered Nov 13 '22 03:11

Yiding


This problem only affects the UIWebView if it is the first subview of the parent view. One alternative way to work around this problem is to add another non-visible empty view to the parent view as the first view. In Interface Builder add a zero size subview and use the Editor->Arrange->Send to Back menu command.

If you're not using Interface Builder, but instead are subclassing the UIWebView, then it can be done by creating a UIView instance variable called scrollFixView and overriding the following methods:

- (void)didMoveToSuperview
{
  [super didMoveToSuperview];

  if ([self superview].subviews.firstObject == self) {
    _scrollFixView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    _scrollFixView.hidden = YES;
    [[self superview] insertSubview:_scrollFixView belowSubview:self];
  }
}

- (void)removeFromSuperview
{
  if (_scrollFixView) {
    [_scrollFixView removeFromSuperview];
    _scrollFixView = nil;
  }

  [super removeFromSuperview];
}
like image 5
ThomasW Avatar answered Nov 13 '22 03:11

ThomasW