Strange padding/margin when using UIWebView(使用 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 中(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 时奇怪的填充/边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 UIWebView 时奇怪的填充/边距
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
