我想將內容添加到項目資源中可用的html文件中。 爲前: - 以下是其內部具有如何將內容添加到iOS中的html文件中
<body >
<div id="abc">
<div>{feed}<br /></div>
<div >{date}</div>
</div>
</body>
我想在它的一些字符串替換{飼料},{日期}和UIwebview
顯示HTML請給我一些指點一下標籤HTML實現它 在此先感謝
我想將內容添加到項目資源中可用的html文件中。 爲前: - 以下是其內部具有如何將內容添加到iOS中的html文件中
<body >
<div id="abc">
<div>{feed}<br /></div>
<div >{date}</div>
</div>
</body>
我想在它的一些字符串替換{飼料},{日期}和UIwebview
顯示HTML請給我一些指點一下標籤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];
UIWebView
方法- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL;
加載它。NSString *str = @"<body >
<div id="abc">
<div>{feed}<br /></div>
<div >{date}</div>
</div>
</body>";
str = [str stringByReplacingOccurrencesOfString:@"{feed}"
withString:@"YourString"];
str = [str stringByReplacingOccurrencesOfString:@"{date}"
withString:@"YourString"];
如果您需要成才其他添加到HTML中使用NSMutableString
代替NSString
使用此:
NSString *feedString = @"Your feed string";
NSString *dateString = @"Your date string";
NSString* descHtmlString = [NSString stringWithFormat:@"<body ><div id="abc"><div>%@<br /></div><div >%@</div></div></body>", feedString, dateString];
u可以使用@代替飼料和日期再通飼料和數據[NSString stringWithForm @「html%@%@」,飼料,日期] – CoolMonster
感謝所有你的答案:) – DAMM108