How to add add-on to UIWebview using Javascript

I want to add an add-on to the UIWebview using Javascript because I am switching the view between full screen and navigation and the navigation bar is hiding the top side of the original pages.

This is the code. It works on some pages, but doesn't work on some pages. Anyone have any ideas to make it work on all pages?

- (void)webViewDidFinishLoad:(UIWebView*)webView {
    //make padding on the top and the bottom of webview
    NSString *padding = @"document.body.style.padding='64px 0px 44px 0px';";
   [webView_ stringByEvaluatingJavaScriptFromString:padding];
}

      

It works great on this page. (Left pic) http://pandodaily.com/2012/03/23/jessica-albas-the-honest-company-raises-27-million-for-non-toxic-baby-products/

It doesn't work on this page. (Right pic.) Http://www.washingtonpost.com/german-entrepreneur-makes-millions-in-eu-through-parallel-pharmaceutical-trade/2012/03/19/gIQAPnZrYS_story.html?wprss=rss_homepage

enter image description hereenter image description here

+3


source to share


1 answer


A friend of mine told me the best solution, so I want to share it.



- (BOOL)iOS5OrHigher {
    NSString *iOSversion = [[UIDevice currentDevice] systemVersion];
    if ([iOSversion compare:@"5.0" options:NSNumericSearch] != NSOrderedAscending) {   
        return YES;
    } else {
        return NO;
    }
}

if ([self iOS5OrHigher]) {
    webView_.scrollView.contentInset = UIEdgeInsetsMake(44.0,0.0,44.0,0.0);
} else {
    UIScrollView *scrollview    = (UIScrollView *)[webView_.subviews objectAtIndex:0];
    scrollview.contentInset     = UIEdgeInsetsMake(44.0,0.0,44.0,0.0);
}

      

+8


source







All Articles