I want to show a local HTML file in my UIWebView
. I can show it, but without any styles or images. Means relative paths are not working but I must use relative paths because there will be much more files. Here is my 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)
// }
}
}
Here is my folder structure:
Here is my 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>