简体   繁体   中英

move or center webview content

如何以编程方式居中或移动加载到Webview对象上的内容?

You would typically use CSS styles to center or position your content. Refer to the Safari CSS Reference and read about the position, top, left, and text-align properties.

To change CSS styles programmatically at runtime from your Objective C code, use -[UIWebView stringByEvaluatingJavaScriptFromString:]. You can pack as much javascript into that string as you need to, but it would be best if you can define some javascript functions in your webview that position the elements based on parameters you pass in from Objective C.

Javascript? sounds new for me, thought that some direct method could easily do that. Is this unique way to do it? I apreciate so much your post, let's start reading safari css reference! If somebody knows any direct method please post it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM