White Space in UIWebView

2019-07-27 08:14发布

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.

enter image description here

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

2条回答
疯言疯语
2楼-- · 2019-07-27 08:43

As discussed use

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

This will take HTML file to top left of webview.

查看更多
Anthone
3楼-- · 2019-07-27 08:44

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.

查看更多
登录 后发表回答