关于在UIWebview中嵌入UIImage的问题;你怎么摆脱边界?

时间:2011-07-12 04:57:45

标签: iphone objective-c ipad uiwebview

以下是我正在使用的代码:

NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

NSString *HTMLData = @"<meta name=\"viewport\" content=\"width=320\"/> <img src=\"image.png\" alt=\"\" width=\"320\" height=\"480\">";
[self.webView loadHTMLString:HTMLData baseURL:[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",imagePath]]];
[self.webView setScalesPageToFit:YES];

Web视图中的图像周围有白色边框。有没有办法让图像占用屏幕?

编辑:添加了截图

The white border around the image is the problem

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

尝试添加将CSS边距属性设置为0px的body标记。生成的HTML应如下所示:

<meta name="viewport" content="width=320"/>
<body style="margin:0px;">
...img tag goes here...
</body>

答案 1 :(得分:1)

您是否尝试过添加border =&#34; 0&#34;

更改:<img src=\"image.png\" alt=\"\" width=\"320\" height=\"480\">

收件人:<img src=\"image.png\" alt=\"\" width=\"320\" height=\"480\ border=\"0\">