Chapter 24. Web Views

A web view (UIWebView) is a versatile renderer of text in various formats, including:

  • HTML
  • PDF
  • RTF, including .rtfd (which must be supplied in a zipped format, .rtfd.zip)
  • Microsoft Word (.doc), Excel (.xls), and PowerPoint (.ppt)
  • Pages, Numbers, and Keynote; before iWork 2009, these must be zipped (e.g. .key.zip), but starting with iWork 2009 they must not be zipped.

In addition to displaying rendered text, a web view is, by default, a web browser. This means that if the user taps, within the web view, on a link that leads to content that the web view can render, the web view by default will automatically fetch that content (possibly over the Internet) and display it. Indeed, a web view is, in effect, a front end for WebKit, the same rendering engine used by Mobile Safari (and, for that matter, by Safari on Mac OS X). A web view can display non-HTML file formats such as PDF, RTF, and so on, precisely because WebKit can display them.

As the user taps links and displays web pages, the web view keeps back-and-forward lists, just like a web browser. Two properties, canGoBack and canGoForward, and two methods, goBack and goForward, let you interact with this list. Your interface could thus contain Back and Forward buttons, like a miniature web browser.

UIWebView is not intended for subclassing. A web view is scrollable, but UIWebView is not a UIScrollView subclass. A web view is zoomable if its scalesToFit property is YES; in that case, it initially scales its ...

Get Programming iOS 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.