将html转换为字符串

将html转换为字符串,html,ios,uiwebview,Html,Ios,Uiwebview,我正在iphone中使用webview,我希望使用标记以html的形式传递数据,这样我就可以添加粗体和斜体的文本,甚至可以添加字符串形式的图片。所以请帮我解决这个问题。任何帮助都是值得的 试试这个: UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 205, 320, 150)]; NSString *filePath = [[NSBundle mainBundle] pathForResource:@"I

我正在iphone中使用webview,我希望使用标记以html的形式传递数据,这样我就可以添加粗体和斜体的文本,甚至可以添加字符串形式的图片。所以请帮我解决这个问题。任何帮助都是值得的

试试这个:

 UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 205, 320, 150)];

 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"ImageName"  ofType:@"png"];

 NSString *htmlString = [NSString stringWithFormat:@"<html><body><b style='color:black'>Deleting your account will:<div style='margin-left:220px; margin-top:-27px'><img src='%@'></div></b><ul style='margin-left:-20px; margin-top:-1px; color:gray; font:Arial; font-size:12x'><li> write some line</li><li> write your line</li><li>write your line</li></ul></body></html>", filePath];

 // you can modified html string as per your need..

 NSString *path = [[NSBundle mainBundle] bundlePath];
 NSURL *baseUrl = [NSURL fileURLWithPath: path];

[webView loadHTMLString:htmlString baseURL:baseUrl];
UIWebView*webView=[[UIWebView alloc]initWithFrame:CGRectMake(0,205,320,150)];
NSString*文件路径=[[NSBundle mainBundle]pathForResource:@“ImageName”类型:@“png”];
NSString*htmlString=[NSString stringWithFormat:@“删除您的帐户将:
  • 写几行
  • 写一行
  • 写一行
”,文件路径]; //您可以根据需要修改html字符串。。 NSString*path=[[NSBundle mainBundle]bundlePath]; NSURL*baseUrl=[NSURL fileURLWithPath:path]; [webView loadHTMLString:htmlString baseURL:baseURL];
您到底想要什么?你想形成一个HTML字符串并在WebView上加载该HTML字符串吗?你正在使用nsurl吗?谢谢兄弟,它工作得很好。。。。。。。