How to load HTMLString in iOS webView
Mar 13, 2018 am 09:41 AMThis time I will show you how to load HTMLString in iOS webView. What are the precautions for loading HTMLString in iOS webView? Here is a practical case, let’s take a look.
CSS needs to translate the ""用"" inside, otherwise OC cannot recognize it. Currently, only the img style is written. Other styles can be added as needed
NSString *CSS= @"<style type=\"text/css\">img{ width:100%;}</style>";
body Translate the "double quotes" inside like the CSS above
NSString *body = @"<h1 style=\"text-align: center;\">关于全市展开卫生检查的通知</h1><img src=\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1494517878331&di=af6cd56216b3212fca2503108f809bfc&imgtype=0&src=http%3A%2F%2Fa.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F0823dd54564e9258b9b28bca9882d158ccbf4e0b.jpg\" </img> <img src=\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1494517770447&di=8672594c95c67bc0444d1770042f6e37&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fforum%2Fpic%2Fitem%2Fdad79612c8fcc3ce558a95db9245d688d63f20d3.jpg\"></img>";
Assemble these components into a complete html format
NSString * htmlString = [NSString stringWithFormat:@"< ;html><meta charset=\"UTF-8\"><header>%@</header><body>%@</body></html>",CSS,body] ;
Finally load it with webView
[self.webView loadHTMLString:htmlString baseURL:nil];
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to add a code block with prompt function
Commonly used WebStorm shortcut keys
Regular expression to verify domestic mobile phone number and landline number
The above is the detailed content of How to load HTMLString in iOS webView. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Display web content using the new JavaFX WebView component in Java 13

How to use python+Flask to realize real-time update and display of logs on web pages

Real-time protection against face-blocking barrages on the web (based on machine learning)

How to configure nginx to ensure that the frps server and web share port 80

Using Jetty7 for Web server processing in Java API development

How to implement form validation for web applications using Golang

How to enable administrative access from the cockpit web UI
