You can use the
UIWebView class to embed web content in your app. To do so, create a
UIWebView object, attach it to a window, and send it a request to load web content. You can also use this class to move back and forward in the history of webpages, and you can even set some web content properties programmatically.
- iOS 2.0+
loadHTMLString(_:baseURL:) method to begin loading local HTML files or the
loadRequest(_:) method to begin loading web content. Use the
stopLoading() method to stop loading, and the
isLoading property to find out if a web view is in the process of loading.
If you allow the user to move back and forward through the webpage history, then you can use the
goForward() methods as actions for buttons. Use the
canGoForward properties to disable the buttons when the user can’t move in a direction.
By default, a web view automatically converts telephone numbers that appear in web content to Phone links. When a Phone link is tapped, the Phone app launches and dials the number. To turn off this default behavior, set the
dataDetectorTypes property with a
UIDataDetectorTypes bitfield that does not contain the
You can also use the
scalesPageToFit property to programmatically set the scale of web content the first time it is displayed in a web view. Thereafter, the user can change the scale using gestures.
UIWebView with Web Inspector. Read Debugging Web Content on iOS to learn how to configure Web Inspector for iOS. Read the rest of Safari Web Content Guide to learn how to create web content that is optimized for Safari on iPhone and iPad.
For information about basic view behaviors, see View Programming Guide for iOS.
Supported File Formats
In addition to HTML content,
UIWebView objects can be used to display other content types, such as Keynote, PDF, and Pages documents. For the best rendering of plain and rich text in your app, however, you should use
In iOS 6 and later, if you assign a value to this view’s
restorationIdentifier property, it attempts to preserve its URL history, the scaling and scrolling positions for each page, and information about which page is currently being viewed. During restoration, the view restores these values so that the web content appears just as it did before. For more information about how state preservation and restoration works, see App Programming Guide for iOS.
For more information about appearance and behavior configuration, see Web Views.
UIWebView class should not be subclassed.