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>
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!