Home Web Front-end H5 Tutorial How to load HTMLString in iOS webView

How to load HTMLString in iOS webView

Mar 13, 2018 am 09:41 AM
web webview

This 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>";
Copy after login

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>";
Copy after login

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];
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Display web content using the new JavaFX WebView component in Java 13 Display web content using the new JavaFX WebView component in Java 13 Aug 01, 2023 pm 01:09 PM

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 How to use python+Flask to realize real-time update and display of logs on web pages May 17, 2023 am 11:07 AM

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

How to use Nginx web server caddy How to use Nginx web server caddy May 30, 2023 pm 12:19 PM

How to use Nginx web server caddy

Real-time protection against face-blocking barrages on the web (based on machine learning) Real-time protection against face-blocking barrages on the web (based on machine learning) Jun 10, 2023 pm 01:03 PM

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 How to configure nginx to ensure that the frps server and web share port 80 Jun 03, 2023 am 08:19 AM

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 Using Jetty7 for Web server processing in Java API development Jun 18, 2023 am 10:42 AM

Using Jetty7 for Web server processing in Java API development

How to implement form validation for web applications using Golang How to implement form validation for web applications using Golang Jun 24, 2023 am 09:08 AM

How to implement form validation for web applications using Golang

How to enable administrative access from the cockpit web UI How to enable administrative access from the cockpit web UI Mar 20, 2024 pm 06:56 PM

How to enable administrative access from the cockpit web UI

See all articles