How to focus UIWebView content on iPhone

I have a map image in UIWebView. It loads by default in the upper left corner. I would like it to be initialized in the center UIWebView.

Does anyone know how to do this?

Thank!

+3
source share
2 answers

If the map image is the only thing on the page, is it wrapped in an html page? If it is at least wrapped in a body tag, you can do the following:

NSString *bodyStyle = @"document.getElementsByTagName('body')[0].style.textAlign = 'center';";
NSString *mapStyle = @"document.getElementById('mapid').style.margin = 'auto';";

[webView stringByEvaluatingJavaScriptFromString:bodyStyle];
[webView stringByEvaluatingJavaScriptFromString:mapStyle];

Let me know exactly how your html is structured, and then I can provide additional information if necessary.

+6
source

, center-aligned div.

<body>
<div align="center">
<!-- Your map here -->
</div>
</body>

, html, UIWebView. javascript-. , , , -.

+2

Source: https://habr.com/ru/post/1747413/


All Articles