使用 UIWebView 时出现奇怪的填充/边距 [英] Strange padding/margin when using UIWebView

查看:22
本文介绍了使用 UIWebView 时出现奇怪的填充/边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含广告的 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(头部、正文、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 时出现奇怪的填充/边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆