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

How to load HTMLString in iOS webView

php中世界最好的语言
Release: 2018-03-13 09:41:48
Original
2919 people have browsed it

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>

%@
%@",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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template