iOS加载HTML, CSS代码

 1     NSString *strHTML = @"<div style=\"text-align:center;\"><img src=\"/Uploads/Editor/2016-11-20/5830edeb561bd.jpg\" alt="" /></div><div style=\"text-align:center;\"><br /></div>";
 2 //    NSString *strHTML = model.goods_datails;
 3     NSMutableString *targerStr = [[NSMutableString alloc] initWithString:strHTML];
 4 //
 5     // 搜索制定字符 在指定位置插入字符串
 6     NSRange range;
 7     range = [targerStr rangeOfString:@"/Uploads/"];
 8     if (range.location != NSNotFound) {
 9 //        NSLog(@"found at location = %lu, length = %lu",(unsigned long)range.location,(unsigned long)range.length);
10         [targerStr insertString:@"http://xiezhongyunshang.com" atIndex:range.location];
11         strHTML = targerStr;
12         NSMutableString *html = [NSMutableString string];
13         
14         [html appendString:@"<html>"];
15         [html appendString:@"<head>"];
16         [html appendString:@"<style>"];
17         [html appendString:@"</style>"];
18         [html appendString:@"</head>"];
19         [html appendString:@"<body style=\"font-size:14px\">"];
20         [html appendString:strHTML];
21         [html appendString:@"</body>"];
22         
23         [html appendString:@"</html>"];
24 
25         // 设置webView 
26         detailView.webView.delegate = self;
27         detailView.webView.dataDetectorTypes = UIDataDetectorTypeAll;
28         detailView.webView.scalesPageToFit = YES;
29         // 加载HTML 
30         [detailView.webView loadHTMLString:html baseURL:[NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]]];
31         [self.mainScrollView addSubview:detailView];

 

posted @ 2016-11-24 09:58  Leo-Wmw  阅读(2369)  评论(0编辑  收藏  举报