Created
April 29, 2012 00:47
-
-
Save davidortinau/2522938 to your computer and use it in GitHub Desktop.
Handle Events from UIWebView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace App.iOS | |
{ | |
public partial class PaperView : UIViewController | |
{ | |
// webView is a UIWebView | |
public override void ViewDidLoad () | |
{ | |
base.ViewDidLoad (); | |
// hide the UINavigationBar | |
this.NavigationController.SetNavigationBarHidden (true, false); | |
// create HTML content with some styling | |
string html = @"<style type='text/css'>body { color: #000000; background-color: white; font-family: 'HelveticaNeue-Light', Helvetica, Arial, sans-serif; padding-bottom: 50px; } h1, h2, h3, h4, h5, h6 { padding: 0px; margin: 0px; font-style: normal; font-weight: normal; } h2 { font-family: 'HelveticaNeue', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: bold; margin-bottom: -10px; padding-bottom: 0px; } h4 { font-size: 16px; } p { font-family: Helvetica, Verdana, Arial, sans-serif; line-height:1.5; font-size: 16px; } .esv-text { padding: 0 0 10px 0; }</style>"; | |
html += "<a href='#back'><img src='Images/btn_back.png'/></a><h1>" + paper.title + "</h1>"; | |
// load HTML into webView | |
webView.LoadHtmlString (html, NSBundle.MainBundle.BundleUrl); | |
// add handler for ShouldStartLoad | |
webView.ShouldStartLoad += webViewShouldStartLoad; | |
} | |
bool webViewShouldStartLoad (UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType) | |
{ | |
// check the url string for the #back anchor | |
if (request.Url.AbsoluteString.IndexOf ("#back") > -1) { | |
this.NavigationController.PopViewControllerAnimated (true); | |
return false; | |
} | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment