iOS – 转译H5代码放到Webview

微信扫一扫,分享到朋友圈

iOS – 转译H5代码放到Webview
NSString *htmlString = @“传入的字符串”
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
htmlString = [htmlString stringByReplacingOccurrencesOfString:@""" withString:@"""];
htmlString = [htmlString stringByReplacingOccurrencesOfString:@">" withString:@">"];
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
htmlString = [@"<style>img{max-width:100%;height:auto;}</style>" stringByAppendingString:htmlString];
NSString *htmlFormat = @"<!DOCTYPE html> <html lang="cn"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> </head> <body> %@ </body> </html>";
dispatch_async(dispatch_get_main_queue(), ^{
NSString *htmlContent = [NSString stringWithFormat:htmlFormat,htmlString];
[self.webView loadHTMLString:htmlContent baseURL:[NSURL URLWithString:@"自己服务器基地址"]];
});

天猫618上线5折新车:大众、日产、比亚迪都有 最低3部iPhone钱

上一篇

乐信考虑合适时机在香港二次上市

下一篇

你也可能喜欢

iOS – 转译H5代码放到Webview

长按储存图像,分享给朋友