2012-03-25 3 views
3

자바 스크립트를 사용하여 UIWebview에 패딩을 추가하고 싶습니다. 뷰를 전체 화면과 탐색 막대 모드로 전환하고 탐색 막대는 원본 페이지의 상단을 숨 깁니다.자바 스크립트를 사용하여 UIWebview에 패딩을 추가하는 방법

이것은 코드입니다. 일부 페이지에서는 작동하지만 일부 페이지에서는 작동하지 않습니다. 누구나 모든 페이지에서 작동하도록하는 아이디어가 있습니까?

- (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]; 
} 

이 페이지에서 제대로 작동합니다. (왼쪽 사진) http://pandodaily.com/2012/03/23/jessica-albas-the-honest-company-raises-27-million-for-non-toxic-baby-products/

이 페이지에서는 작동하지 않습니다. (오른쪽 그림) 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 here enter image description here

답변

8

내 친구가 나에게 더 나은 솔루션을했다, 그래서 나는 그것을 공유하고자합니다.

- (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); 
} 
관련 문제