NSString *htmlString = @“传入的字符串”
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<" withString:@"<"];htmlString=[htmlStringstringByReplacingOccurrencesOfString:@"""withString:@"\""];htmlString=[htmlStringstringByReplacingOccurrencesOfString:@">"withString:@">"]; htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&" 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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
网友评论