title: UIWebview remove padding / margin
body: <p>I am loading a PDF into a <code>UIWebview</code> and I changed the background color to clear and set opaque to false. However now there is a padding or margin in my <code>UIWebView</code> that I would like to remove so the <code>UIWebview</code> is the screen.</p>
  
  <p>I created a <code>UIWebview</code> like so:</p>
  
  <pre><code>let webview = UIWebView()
  webview.frame = self.view.bounds
  webview.scrollView.frame = webview.frame
  webview.userInteractionEnabled = true
  webview.scalesPageToFit = true
  webview.becomeFirstResponder()
  webview.delegate = self
  webview.scrollView.delegate = self
  webview.opaque = false
  webview.backgroundColor = UIColor.clearColor()
  self.view.addSubview(webview)
  webview.loadRequest(NSURLRequest(URL:url))
  webview.gestureRecognizers = [pinchRecognizer, panRecognizer]
  </code></pre>
  
  <p>and I applied this to the webViewDidFinishLoad method</p>
  
  <pre><code>func webViewDidFinishLoad(webView: UIWebView) {
          let padding = "document.body.style.margin='0';document.body.style.padding = '0'"
          webView.stringByEvaluatingJavaScriptFromString(padding)
  }
  </code></pre>
  
  <p>but there is still a padding or margin, it looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/uc6tF.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/uc6tF.jpg" alt="enter image description here"></a></p>
  
  <p>How do I fix this?</p>
  
  <p>The Reason why I need this fixed is because I am going to be saving this UIWebView as a PDF and when I save it, that extra spacing is there also, here is my PDF generate code:</p>
  
  <pre><code>func drawPDFUsingPrintPageRenderer(printPageRenderer: UIPrintPageRenderer) -&gt; NSData! {
  
          let data = NSMutableData()
  
  
          UIGraphicsBeginPDFContextToData(data, CGRectZero, nil)
  
  
          UIGraphicsBeginPDFPage()
  
  
          printPageRenderer.drawPageAtIndex(0, inRect: UIGraphicsGetPDFContextBounds())
  
  
          UIGraphicsEndPDFContext()
  
  
          return data
      }
  </code></pre>
  
  <p>and more</p>
  
  <pre><code>let screenHeight = appDelegate.webview!.scrollView.bounds.size.height
  
          let heightStr = appDelegate.webview!.scrollView.bounds.size.height
  
          let height = heightStr
  
          let pages = ceil(height / screenHeight)
  
          let pdfMutableData = NSMutableData()
  
          UIGraphicsBeginPDFContextToData(pdfMutableData, appDelegate.webview!.scrollView.bounds, nil)
  
          for i in 0..&lt;Int(pages)
          {
  
              if (CGFloat((i+1)) * screenHeight  &gt; CGFloat(height)) {
                  var f = appDelegate.webview!.scrollView.frame
                  f.size.height -= ((CGFloat((i+1)) * screenHeight) - CGFloat(height));
                  appDelegate.webview!.scrollView.frame = f
              }
  
              UIGraphicsBeginPDFPage()
  
              let currentContext = UIGraphicsGetCurrentContext()
  
              appDelegate.webview!.scrollView.setContentOffset(CGPointMake(0, screenHeight * CGFloat(i)), animated: false)
  
              appDelegate.webview!.scrollView.layer.renderInContext(currentContext!)
  
          }
  
          UIGraphicsEndPDFContext()
  </code></pre>