【问题标题】:Displaying HTML in iPhone app在 iPhone 应用程序中显示 HTML
【发布时间】:2011-08-12 06:56:07
【问题描述】:
如何在textview iphone中打开url??
是否可以用links,photos 和所有html entities 显示数据???
【问题讨论】:
标签:
iphone
html
objective-c
uiwebview
uitextview
【解决方案1】:
您可以使用 UIWebView 从文件中加载静态包含; html、照片、css、javascript。
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:htmlString baseURL:baseURL];
然后将“index.html”作为普通 HTML 标准添加到您的项目中。
<html>
<head><title>Hello</title></head>
<body>
<img src="icon.png"/>
<p>Test</p>
</body>
</html>
【解决方案2】:
UITextView 控制是不可能的。使用UIWebView 或制作您自己的自定义控件。