| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iPhone OS 2.0 and later. |
| Declared in | UIWebView.h |
| Related sample code |
You use the UIWebView class to embed web content in your application. To do so, you simply 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.
Use the loadRequest: method to begin loading web content, the stopLoading method to stop loading, and the loading 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 goBack and goForward methods as actions for buttons. Use the canGoBack and 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 application launches and dials the number. Set the detectsPhoneNumbers property to NO to turn off this default behavior.
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.
Set the delegate property to an object conforming to the UIWebViewDelegate protocol if you want to track the loading of web content.
Read Safari Web Content Guide for how to create web content that is compatible with and optimized for displaying in Safari on iPhone and your web views.
The UIWebView class should not be subclassed.
delegate property
– loadData:MIMEType:textEncodingName:baseURL:
– loadHTMLString:baseURL:
– loadRequest:
request property
loading property
– stopLoading
– reload
canGoBack property
canGoForward property
– goBack
– goForward
detectsPhoneNumbers property
scalesPageToFit property
dataDetectorTypes property
For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.
A Boolean value indicating whether the receiver can move backward. (read-only)
@property(nonatomic, readonly, getter=canGoBack) BOOL canGoBack
If YES, able to move backward; otherwise, NO.
UIWebView.hA Boolean value indicating whether the receiver can move forward. (read-only)
@property(nonatomic, readonly, getter=canGoForward) BOOL canGoForward
If YES, able to move forward; otherwise, NO .
UIWebView.hThe types of data converted to clickable URLs in the web view’s content.
@property(nonatomic) UIDataDetectorTypes dataDetectorTypes
You can use this property to specify the types of data (phone numbers, http links, and so on) that should be automatically converted to clickable URLs in the web view. When clicked, the web view opens the application responsible for handling the URL type and passes it the URL.
UIWebView.hThe receiver’s delegate.
@property(nonatomic, assign) id<UIWebViewDelegate> delegate
The delegate is sent messages when content is loading. See UIWebViewDelegate Protocol Reference for the optional methods this delegate may implement.
Important: Before releasing an instance of UIWebView for which you have set a delegate, you must first set its delegate property to nil. This can be done, for example, in your dealloc method.
UIWebView.hA Boolean value indicating whether telephone number detection is on. (Deprecated. Use dataDetectorTypes instead.)
@property(nonatomic) BOOL detectsPhoneNumbers
If YES, telephone number detection is on; otherwise, NO. If a webpage contains numbers that can be interpreted as phone numbers, but are not phone numbers, you can turn off telephone number detection by setting this property to NO. The default value is YES on devices that have phone capabilities.
The functionality provided by this property has been superseded by the dataDetectorTypes property.
UIWebView.hA Boolean value indicating whether the receiver is done loading content. (read-only)
@property(nonatomic, readonly, getter=isLoading) BOOL loading
If YES, the receiver is still loading content; otherwise, NO.
UIWebView.hThe URL request identifying the location of the content to load. (read-only)
@property(nonatomic, readonly, retain) NSURLRequest *request
UIWebView.hA Boolean value determining whether the webpage scales to fit the view and the user can change the scale.
@property(nonatomic) BOOL scalesPageToFit
If YES, the webpage is scaled to fit and the user can zoom in and zoom out. If NO, user zooming is disabled. The default value is NO.
UIWebView.hLoads the previous location in the back-forward list.
- (void)goBack
UIWebView.hLoads the next location in the back-forward list.
- (void)goForward
UIWebView.hSets the main page contents, MIME type, content encoding, and base URL.
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL
The content for the main page.
The MIME type of the content.
The IANA encoding name as in utf-8 or utf-16.
The base URL for the content.
UIWebView.hSets the main page content and base URL.
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
The content for the main page.
The base URL for the content.
UIWebView.hConnects to a given URL by initiating an asynchronous client request.
- (void)loadRequest:(NSURLRequest *)request
A URL request identifying the location of the content to load.
To stop this load, use the stopLoading method. To see whether the receiver is done loading the content, use the loading property.
UIWebView.hReloads the current page.
- (void)reload
UIWebView.hStops the loading of any web content managed by the receiver.
- (void)stopLoading
Stops any content in the process of being loaded by the main frame or any of its children frames. Does nothing if no content is being loaded.
UIWebView.hReturns the result of running a script.
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
The script to run.
The result of running script or nil if it fails.
JavaScript execution time is limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, Safari stops executing the script. This is likely to occur at a random place in your code, so unintended consequences may result. This limit is imposed because JavaScript execution may cause the main thread to block, so when scripts are running, the user is not able to interact with the webpage.
JavaScript allocations are also limited to 10 MB. Safari raises an exception if you exceed this limit on the total memory allocation for JavaScript.
UIWebView.hConstant indicating the user’s action.
enum {
UIWebViewNavigationTypeLinkClicked,
UIWebViewNavigationTypeFormSubmitted,
UIWebViewNavigationTypeBackForward,
UIWebViewNavigationTypeReload,
UIWebViewNavigationTypeFormResubmitted,
UIWebViewNavigationTypeOther
};
typedef NSUInteger UIWebViewNavigationType;
UIWebViewNavigationTypeLinkClickedUser tapped a link.
Available in iPhone OS 2.0 and later.
Declared in UIWebView.h.
UIWebViewNavigationTypeFormSubmittedUser submitted a form.
Available in iPhone OS 2.0 and later.
Declared in UIWebView.h.
UIWebViewNavigationTypeBackForwardUser tapped the back or forward button.
Available in iPhone OS 2.0 and later.
Declared in UIWebView.h.
UIWebViewNavigationTypeReloadUser tapped the reload button.
Available in iPhone OS 2.0 and later.
Declared in UIWebView.h.
UIWebViewNavigationTypeFormResubmittedUser resubmitted a form.
Available in iPhone OS 2.0 and later.
Declared in UIWebView.h.
UIWebViewNavigationTypeOtherSome other action occurred.
Available in iPhone OS 2.0 and later.
Declared in UIWebView.h.
UIWebView.hLast updated: 2009-06-04