A view that embeds web content in your app.
SDK
- iOS 2.0–12.0Deprecated
Framework
- UIKit
Declaration
class UIWebView : UIView
Overview
Note
In apps that run in iOS 8 and later, use the WKWeb class instead of using UIWeb. Additionally, consider setting the WKPreferences property java to false if you render files that are not supposed to run JavaScript.
Important
An iOS app linked on or after iOS 10.0 must include in its Info file the usage description keys for the types of data it needs to access or it will crash. To access a user’s photo data specifically, it must include NSPhotoLibraryUsageDescription and NSCameraUsageDescription.
Use the load method to begin loading local HTML files or the load method to begin loading web content. Use the stop method to stop loading, and the is 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 go and go methods as actions for buttons. Use the can and can 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 data property with a UIData bitfield that does not contain the phone flag.
You can also use the scales 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.
Set the delegate property to an object conforming to the UIWeb protocol if you want to track the loading of web content.
Important
You should not embed UIWeb or UITable objects in UIScroll objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
You can easily debug the HTML, CSS, and JavaScript contained inside a UIWeb 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, UIWeb 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 UIText instead.
State Preservation
In iOS 6 and later, if you assign a value to this view’s restoration 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.
Subclassing Notes
The UIWeb class should not be subclassed.