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 = @"'64px 0px 44px 0px';";
   [webView_ stringByEvaluatingJavaScriptFromString:padding];


It works great on this page. (Left pic)

It doesn't work on this page. (Right pic.) Http://

enter image description hereenter image description here


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);




All Articles