您的位置:首页 > Web前端 > HTML

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: