Xcode创建一个本地的Html
2015-10-08 12:09
459 查看
怎样自己创建一个本地的Html
1创建文件
2.在里面写
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
img{
width: 100%;
}
</style>
</head>
<body>
</body>
</html>
3.调用
cell中
- (void)awakeFromNib{
self.webView.delegate =
self;
self.webView.userInteractionEnabled =
NO;
}
- (void)setWebContent:(NSString *)webContent{
_webContent = webContent;
if (_webContent) {
[self.webView
loadHTMLString:[self
addCssWithContent:_webContent]
baseURL:nil];
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
if (!loaded) {
NSString *height_str= [webView
stringByEvaluatingJavaScriptFromString:
@"document.body.offsetHeight"];
CGFloat height = [height_str
floatValue];
if (self.webLoadDoneBlock) {
self.webLoadDoneBlock(height);
}
loaded = YES;
}
}
- (NSString *)addCssWithContent:(NSString*)content {
NSMutableString *htmlText = [NSMutableString
stringWithContentsOfFile:[[NSBundle
mainBundle] pathForResource:@"htmlText"
ofType:nil]
encoding:NSUTF8StringEncoding
error:nil];
[htmlText
insertString:content
atIndex:htmlText.length-15];
return htmlText;
}
ViewController中
ProdDetailWebCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"ProdDetailWebCell"];
cell.webContent =
_webContent;
cell.webLoadDoneBlock = ^(CGFloat height){
_webHeight = height;
[tableView
reloadData];
};
return cell;
1创建文件
2.在里面写
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
img{
width: 100%;
}
</style>
</head>
<body>
</body>
</html>
3.调用
cell中
- (void)awakeFromNib{
self.webView.delegate =
self;
self.webView.userInteractionEnabled =
NO;
}
- (void)setWebContent:(NSString *)webContent{
_webContent = webContent;
if (_webContent) {
[self.webView
loadHTMLString:[self
addCssWithContent:_webContent]
baseURL:nil];
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
if (!loaded) {
NSString *height_str= [webView
stringByEvaluatingJavaScriptFromString:
@"document.body.offsetHeight"];
CGFloat height = [height_str
floatValue];
if (self.webLoadDoneBlock) {
self.webLoadDoneBlock(height);
}
loaded = YES;
}
}
- (NSString *)addCssWithContent:(NSString*)content {
NSMutableString *htmlText = [NSMutableString
stringWithContentsOfFile:[[NSBundle
mainBundle] pathForResource:@"htmlText"
ofType:nil]
encoding:NSUTF8StringEncoding
error:nil];
[htmlText
insertString:content
atIndex:htmlText.length-15];
return htmlText;
}
ViewController中
ProdDetailWebCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"ProdDetailWebCell"];
cell.webContent =
_webContent;
cell.webLoadDoneBlock = ^(CGFloat height){
_webHeight = height;
[tableView
reloadData];
};
return cell;