NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString *htmlString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"index_pic1" ofType:@"html"] encoding:NSUTF8StringEncoding error:nil];
[self.moblieWebView loadHTMLString:htmlString baseURL:baseURL];
把我自己获得的html 填充进去 没有任何问题self.finalStr = [NSMutableString string]; //初始化拼装字符串
self.moblieWebView = [[[UIWebView alloc]initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height - kTabBarHeight) ] autorelease];
self.moblieWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.moblieWebView.dataDetectorTypes = UIDataDetectorTypeNone; //去掉数字下划线
NSString *resourcePath = [ [NSBundle mainBundle] resourcePath];
NSURL *baseURL = [NSURL fileURLWithPath:resourcePath];
NSString *HeadPath = [resourcePath stringByAppendingPathComponent:@"Head.html"];
NSString *startString=[[[NSString alloc] initWithContentsOfFile:HeadPath encoding:NSUTF8StringEncoding error:nil] autorelease];
//html head
[self.finalStr appendString:startString];
//加载动态html数据
[self.finalStr appendString:@"<body>\n"];
[self.finalStr appendString:@"<div id=\"caption\">\n"];
//加载标题
[self.finalStr appendString:@"<div id=\"title\">\n"];
[self.finalStr appendString:@"<h1>"];
[self.finalStr appendFormat:@"标题"]; //标题
[self.finalStr appendString:@"</h1>\n"];
[self.finalStr appendString:@"</div>\n"];
//加载日期
[self.finalStr appendString:@"<div id=\"date\">\n"];
[self.finalStr appendString:@"<h2>"];
[self.finalStr appendFormat:@"2012-10-09"]; //日期
[self.finalStr appendString:@"</h2>\n"];
[self.finalStr appendString:@" </div>\n"];
[self.finalStr appendString:@"<div id=\"text\">\n"];
//显示的图片
[self.finalStr appendString:@"<a href = \"javascript:void(0)\" onclick = \"document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'\"><div id=\"pic\"><img class=\"img-wrapper\" src=\"http://www.acwind.net/images/icdb_pics_collect/856_3723.jpg\"></div>\n"];
//显示的图片上的加号
[self.finalStr appendFormat:@"<div id=\"pic\"><img class=\"plus\" src=\"[email protected]\" style=\"position:absolute; \"/></div></a> "];
//点击放大后 图片上的叉号
[self.finalStr appendString:@"<div id=\"light\" class=\"white_content\">"];
[self.finalStr appendString:@"<a href = \"javascript:void(0)\" onclick = \"document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'\"><img id=\"button\" class=\"funtion_button\" src=\"[email protected]\" style=\"display:block;\"/><img id=\"EnlargePhoto\" src=\"http://www.acwind.net/images/icdb_pics_collect/856_3723.jpg\" onload=\"javascript:DrawImage(this)\"/ ></a></div>"];
[self.finalStr appendString:@"<div id=\"fade\" class=\"black_overlay\"></div>"];
//简介
[self.finalStr appendFormat:@"<p>简介 简介 简介</p>"];
//内容
[self.finalStr appendFormat:@"<p>这里是内容</p>"];
//时间
[self.finalStr appendFormat:@"<p>这里是时间</p>"];
//作者
[self.finalStr appendFormat:@"<p>这里是作者</p>"];
//html end
[self.finalStr appendFormat:@"</div>\n</div>\n</body>\n</html>\n"];
[self.moblieWebView loadHTMLString:self.finalStr baseURL:nil];
self.moblieWebView.scalesPageToFit = YES;
[self.view addSubview:self.moblieWebView];
[self.moblieWebView loadHTMLString:self.finalStr baseURL:baseURL];
完美解决!
至今没搞懂 苹果底层 是怎么处理的 即使是自己拼装的字符串 也不能让 baseUrl 这个属性为空~
也欢迎有大侠帮小菜解答一下