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

How to load HTMLString in iOS webView

php中世界最好的语言
php中世界最好的语言Original
2018-03-13 09:41:482943browse

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>";

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>670df730e2ddba67da7ae865e6ff38161aa9e5d373740b65a0cc8f0a02150c53%@ab946e7546ab66a280dd9c9f9310ecd56c04bd5ca3fcae76e30b72ad730ca86d%@36cc49f0c466276486e50c850b7e495673a6ac4ed44ffec12cee46588e518a5e",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!

Statement:
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