我想向项目资源中可用的html文件添加内容。
例如:-下面是html,里面有一些标签
<body >
<div id="abc">
<div>{feed}<br /></div>
<div >{date}</div>
</div>
</body>
我想用其中的一些字符串替换{feed},{date}并在
UIwebview
中显示该html请给我一些指导以实现它
提前致谢
最佳答案
//Get your HTML file path.
NSString * htmlFilePath = [[NSBundle mainBundle] pathForResource:@"YOUR_FILE_NAME" ofType:@"html"];
//get the file content to a NSString.
NSString *htmlContentString = [NSString stringWithContentsOfFile:htmlFilePath encoding:NSUTF8StringEncoding error:nil];
// Then you need to replace a string (say 'stringA') with new string (say 'stringB')
htmlContentString = [htmlContentString stringByReplacingOccurrencesOfString:stringA withString:stringB];
//Then load the new HTML string to your webView
[yourWebView loadHTMLString:htmlContentString baseURL:nil];
关于ios - 如何在iOS中将内容添加到html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21930484/