将html转换为字符串

时间:2013-12-09 17:38:25

标签: html ios uiwebview

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

1 个答案:

答案 0 :(得分:1)

试试这个:

 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];