【发布时间】:2015-12-01 10:11:33
【问题描述】:
我想在我的UIWebView 中显示一个本地 HTML 文件。我可以展示它,但没有任何样式或图像。意味着相对路径不起作用,但我必须使用相对路径,因为会有更多文件。这是我的WebViewController:
class WebViewController: UIViewController {
@IBOutlet weak var web1: UIWebView!
var fileName : String!
override func viewDidLoad() {
if let file = self.fileName{
print("got: "+file)
}
let url = NSBundle.mainBundle().URLForResource(self.fileName, withExtension:"html")
let request = NSURLRequest(URL: url!)
web1.loadRequest(request)
//this does not work, webview gets blank (white)
// let path: String? = NSBundle.mainBundle().pathForResource("AceVetBolus", ofType: "html", inDirectory: "HTMLFiles")
// if let unwrappedPath = path {
// let requestURL = NSURL(string: unwrappedPath)
// let request = NSURLRequest(URL: requestURL!)
//
// web1.loadRequest(request)
// }
}
}
这是我的文件夹结构:
这是我的html:
<!DOCTYPE html>
<html lang="en-US">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<link rel="stylesheet" type="text/css" href="./css/product.css" />
</head>
<body>
<h2> Ace-Vet Bolus</h2>
<div class="title">Composition:</div>
<p> Each Bolus contains Paracetamol BP 2000 mg. </p>
<div class="title">Indication:</div>
<img src="./images/chicken_icon.png"/>
<p>Recovery from fever, pain (headache, earache, body ache, neuralgia,
pain due to intestinal inflammation, rheumatoid fever, post vaccination pain,
post delivery pain, post operative pain) and tissue swollen resulting from trauma,
injury, burn or any other infectious diseases of both Animal & Poultry.</p>
<div class="title">Dosage and administration:</div>
<p>Animal: 1 bolus / 130-140 kg body weight (15 mg/kg body weight), 3 times daily.
Poultry: 1 bolus should be mixed with 10 litre drinking water & administered 2 - 3 times daily.
Or as directed by the registered Veterinary physician.</p>
<div class="title">Contraindication:</div>
<p>Ace-Vet<sup>®</sup> Bolus should be used with caution in those animals which are renally or hepatically impaired.</p>
<div class="title">Use in pregnancy and lactation:</div>
<p>Ace-Vet<sup>®</sup> Bolus is safe in all stages of pregnancy and lactation.</p>
<div class="title">Side effects:</div>
<p>Side effects of Ace-Vet<sup>®</sup> Bolus are significantly mild,
though hematological reactions have been reported. Pancreatitis,
skin rashes and other allergic reactions occur occasionally.</p>
<div class="title">Storage:</div>
<p>Protected from light, store in a cool and dry place. Keep out of reach of children.</p>
<div class="title">Pack Size:</div>
<p>10x4 Bolus.</p>
</body>
</html>
【问题讨论】:
-
能否请您发布您的 HTML 代码。
-
HTML 没问题。在浏览器中正常运行。你还需要它吗?
-
是的,如果可能的话,你能在这里发帖吗....因为我试图在我身边产生同样的问题