White Space in UIWebView

我的未来我决定 提交于 2019-12-24 14:18:37

问题


I am working on an app in which I am using UIWebView. To make UIWebView editable, I have used an HTML file and have set its attribute contenteditable=true. To perform some operation, I am using JavaScript.

I have set css in HTML file. Below is the code.

<style>
            #test
            {
                padding-left:5px;
                padding-right:5px;
                background-color:green;
                text-align:left;
                width:100%;
                font-family: "Times New Roman";
                border-radius:5px;
            }

 </style>

Now, my problem is I am getting a white margin of about 10-15px from top, bottom and left side between UIWebView and HTML file loaded in UIWebView. Here I am attaching screenshot for same.



I have just started working on HTML and JavaScript(no prior knowledge) and not getting where the problem is.

回答1:


As discussed use

{position:absolute;top:0px;left:0px;}

This will take HTML file to top left of webview.




回答2:


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.



来源:https://stackoverflow.com/questions/18329297/white-space-in-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!