Last active
August 29, 2015 14:07
-
-
Save zummenix/c9623325e2dda4a02da1 to your computer and use it in GitHub Desktop.
Fix a black frame around a pdf viewer in UIWebView.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// ... | |
[self fixWebView:self.webView recursiveView:self.webView loadingFinished:NO]; | |
} | |
- (void)fixWebView:(UIWebView *)webView recursiveView:(UIView *)view loadingFinished:(BOOL)finished | |
{ | |
if (finished) { | |
view.alpha = 1.0; | |
BOOL showsHorizontalScrollIndicator = webView.scrollView.showsHorizontalScrollIndicator; | |
BOOL showsVerticalScrollIndicator = webView.scrollView.showsVerticalScrollIndicator; | |
webView.scrollView.showsHorizontalScrollIndicator = NO; | |
webView.scrollView.showsVerticalScrollIndicator = NO; | |
webView.scrollView.showsHorizontalScrollIndicator = showsHorizontalScrollIndicator; | |
webView.scrollView.showsVerticalScrollIndicator = showsVerticalScrollIndicator; | |
} else { | |
view.alpha = 0.0; | |
} | |
if ([NSStringFromClass([view class]) isEqualToString:@"UIWebPDFView"]) { | |
view.backgroundColor = [UIColor whiteColor]; | |
return; | |
} | |
for (UIView *subview in [view subviews]) { | |
[self fixWebView:webView recursiveView:subview loadingFinished:finished]; | |
} | |
} | |
- (void)fixWebView | |
{ | |
[self fixWebView:self.webView recursiveView:self.webView loadingFinished:YES]; | |
} | |
#pragma mark - UIWebViewDelegate | |
- (void)webViewDidFinishLoad:(UIWebView *)webView | |
{ | |
[self performSelector:@selector(fixWebView) withObject:nil afterDelay:0.5]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment