Developer tip: Easily load a local HTML file into a UIWebView with image, CSS, and JavaScript resources

A small victory was had this morning when I finally figured out the magic combination of programming bits to make local UIWebViews work with local resources in an iOS app.

Instead of fighting with building the sBASSdrum help menus out of scrollable container views, it seemed like the best and easiest way to show the text was to load a local HTML file. This turns out to be easy but there are a number of gotchas. As I wrote on StackOverflow:

  1. Make sure all your bundle resources are unique—directories get flattened
  2. JavaScript files will be in the wrong Build Phase
  3. Use UIWebView’s loadRequest:

If you follow this recipe victory will be yours. Here is a Gist:

Even better, to make the background of the UIWebView transparent so you can see graphics behind it, follow this formula:

  1. Click on the UIWebView
  2. Set the background to Clear Color (not transparent)
  3. Unset the “opaque” property