Strange padding/margin when using UIWebView

前端 未结 3 1398
-上瘾入骨i
-上瘾入骨i 2020-12-09 09:12

I am creating an app that is having a UIWebView which contains an advert. The size of the view is the same as the advert (image) itself. Still, there is a white margin/paddi

3条回答
  •  有刺的猬
    2020-12-09 09:30

    Basically, all browsers add in that whitespace around the edges of the page to be backwards-compatible with like Netscape 1. In the HTML you're loading into the web view, you can use CSS to remove that:

    body { margin: 0; padding: 0; }
    

    If you're not loading HTML into your web view, but just the direct URL for an image file, I suggest either a) wrapping that in some basic HTML (head, body, an img tag), or b) downloading the image yourself (say with NSURLConnection), and displaying it directly in a UIImageView.

提交回复
热议问题