0

Does anyone know how to remove the shadow and page number for a pdf document presented in UIWebView?

I've found methods for non-Swift, but nothing for Swift.

Any help would be greatly appreciated.

UPDATE

I've found a Objective C method:

for (UIView* subView in [webView subviews])
{
    if ([subView isKindOfClass:[UIScrollView class]]) {
        for (UIView* shadowView in [subView subviews])
        {
            if ([shadowView isKindOfClass:[UIImageView class]]) {
                [shadowView setHidden:YES];
            }
        }
    }
}

Can anyone point me in the direction of a Swift method, or how to convert this to Swift. I have tried but getting nowhere I'm afraid.

Thanks in advance

Nicholas Farmer
  • 773
  • 7
  • 32
  • I think this is what you are looking for: http://stackoverflow.com/questions/7045769/remove-or-change-color-of-frame-around-uiwebview-document-display – Coder1000 Apr 24 '16 at 13:30
  • Thanks Coder1000 - but do you know of a swift version or basically how to convert the answer into swim. I have tried but I'm not getting anywhere and this is the final aspect to my app. Thanks in advance – Nicholas Farmer Apr 24 '16 at 14:03

2 Answers2

2

Try this great answer:

func webViewDidFinishLoad(_ webView: UIWebView) {
    for shadowView in self.webView.scrollView.subviews {
        if !shadowView.isKind(of: UIImageView.self) {
            shadowView.subviews[0].layer.shadowColor = UIColor.clear.cgColor
        } else {
            shadowView.layer.shadowColor = UIColor.clear.cgColor
        }
    }
}

Don't forget to set your ViewController as the delegate of the webView

Leon
  • 3,614
  • 1
  • 33
  • 46
-2

Your problem is the "non-Swift" part. You should learn how to read Objective-C code snippets and write them in Swift.

webView.opaque = false
webView.backgroundColor = UIColor.clearColor()
Mundi
  • 79,884
  • 17
  • 117
  • 140
  • I agree Mundi, I'm relatively new to using swift. However in regard to the question, your code doesn't seem to change the 'shadow' -it's still present. I'll post a link to the non-swift answer: http://stackoverflow.com/questions/21219562/is-it-possible-to-remove-page-1-of-20-view-in-a-uiwebview-when-displaying-pd – Nicholas Farmer Apr 24 '16 at 13:58
  • 2
    Hi Mundi, no offence meant, but I didn't up vote as the code doesn't achieve what I'm looking for I'm afraid. The 'shadow' is still present and so are the page numbers (however from the code you supplied I wasn't expecting that to be remedied). If you could help point me in the right direction of achieving those 2 things then I would be delighted to up vote :) – Nicholas Farmer Apr 24 '16 at 14:11