Load Local ContentTable of contentsThis recipe shows how to load a local web page in a UIWebView control. Sample Code: Related Apple Documentation: Using UIWebView to display select document types RecipeTo show local Html content in a UIWebView:
webView = new UIWebView (View.Bounds); View.AddSubview(webView);
string fileName = "Content/Home.html"; // remember case-sensitive string localHtmlUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName); webView.LoadRequest(new NSUrlRequest(new NSUrl(localHtmlUrl, false))); webView.ScalesPageToFit = false; Additional InformationHtml generated in code can also be displayed, which is useful for customizing the content. To display an Html string, use the LoadHtmlString method instead of LoadRequest. Passing the path to the Content directory helps the web view resolve relative Urls in the Html, such as links, images, CSS, etc. string contentDirectoryPath = Path.Combine (NSBundle.MainBundle.BundlePath, "Content/"); string html = "<html><a href='Home.html'>Click me</a></html>"; webView.LoadHtmlString(html, new NSUrl(contentDirectoryPath, true));
|