我正在创建一个应用程序,它的 UIWebView 包含一个广告.视图的大小与广告(图像)本身相同.尽管如此,在 UIWebView 内部,图像的上方和左侧仍有某种白色边距/填充.查看链接图片:
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/padding of some kind above and to the left of the image, inside the UIWebView. Check out the linked image:
实际上,由于这种填充,图像也被向下和向右推.
Actually, the image is pushed down and to the right due to this padding also.
知道我应该如何删除白色填充吗?
Any idea how I should remove the white padding?
提前致谢!
基本上,所有浏览器都会在页面边缘添加空白,以便与 Netscape 1 向后兼容.在您加载的 HTML 中web 视图,你可以使用 CSS 来移除它:
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; }
如果您没有将 HTML 加载到 Web 视图中,而只是将图像文件的直接 URL 加载到其中,我建议 a) 将其包装在一些基本的 HTML 中(head、body、img
标记),或者 b) 自己下载图像(例如使用 NSURLConnection
),并直接在 UIImageView
中显示它.
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
.
这篇关于使用 UIWebView 时奇怪的填充/边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!