iOS 转译H5代码放到Webview

NSString *htmlString = @“传入的字符串”

htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];htmlString=[htmlStringstringByReplacingOccurrencesOfString:@"""withString:@"\""];htmlString=[htmlStringstringByReplacingOccurrencesOfString:@">"withString:@">"];    htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];    htmlString = [@"<style>img{max-width:100%;height:auto;}</style>" stringByAppendingString:htmlString];    NSString *htmlFormat = @"<!DOCTYPE html><head> </head><body>%@</body></html>";    dispatch_async(dispatch_get_main_queue(), ^{        NSString *htmlContent = [NSString stringWithFormat:htmlFormat,htmlString];        [self.webView loadHTMLString:htmlContent baseURL:[NSURL URLWithString:@"自己服务器基地址"]];    });

作者:biubiuboom

链接:https://www.jianshu.com/p/e7296b5618b6

来源:简书

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容