美文网首页
iOS 转译H5代码放到Webview

iOS 转译H5代码放到Webview

作者: 夭Y夭 | 来源:发表于2019-10-28 09:59 被阅读0次

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

来源:简书

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

相关文章

网友评论

      本文标题:iOS 转译H5代码放到Webview

      本文链接:https://www.haomeiwen.com/subject/wwpvvctx.html