Javatpoint Logo
Javatpoint Logo

WebView

WebView can be defined as an object which can display the interactive web content and load HTML strings within the iOS application for an in-app browser. It is an instance of the WKWebView class, which inherits the UIView class.

As mentioned above, to load the web content in the iOS application, we can use the WebView object. All we need to do is, create a WKWebView object, set it as a view, and send it a request to load web content.

WKWebView Properties and Methods

The WKWebView class contains properties and methods that can be used to customize the behavior of the webview. We can let the user navigate in a backward and forward direction using goBack() and goForward() methods. To check whether the user can move in a particular direction, we can use the Boolean properties canGoBack and canGoForward.

WebView also converts the phone number into the links on tapping which, the user is redirected to the dialer pad with the tapped number prefilled.

WKWebView Properties

SN Property Description
1 var scrollView: UIScrollView It represents the scrollview associated with the web view.
2 var title: String? It is a string object which represents the page title.
3 var url: URL? It is an instance of the URL class, which represents the active URL.
4 var customUserAgent: String? It is a string object which represents custom user agent string.
5 var serverTrust: SecTrust? A SecTrustRef object for the currently committed navigation.
6 var navigationDelegate: WKNavigationDelegate? It is the web view's navigation delegate.
7 var uiDelegate: WKUIDelegate? It represents the web view's UI delegate.
8 var estimatedProgress: Double It is a double type object which represents the estimate of what fraction of the current navigation has been loaded.
9 var hasOnlySecureContent: Bool It is a Boolean type value that determines whether all resources on the page have been loaded through securely encrypted connections.
10 var isLoading: Bool It is a Boolean type value that indicates whether the view is currently loading the web content.
11 var allowsMagnification: Bool It is a Boolean type value that indicates whether magnify gestures will change the web view's magnification.
12 var magnification: CGFloat It is the factor by which the web page content is currently scaled.
13 var allowsBackForwardNavigationGestures: Bool A Boolean value indicating whether horizontal swipe gestures will trigger back-forward list navigations.
14 var backForwardList: WKBackForwardList It is the web view's back forward list.
15 var canGoBack: Bool It is a Boolean type value that indicates whether there is a back item that exists in the back-forward list.
16 var canGoForward: Bool It is a Boolean type value that indicates whether there is a forward item that exists in the back-forward list.
17 var allowsLinkPreview: Bool It is a Boolean type value that controls whether tapping on a link would display the preview of the link destination.

WKWebView Methods

SN Method Description
1 func loadHTMLString(String, baseURL: URL?) -> WKNavigation? This method is used to set the webpage contents and base URL.
2 func reload() -> WKNavigation? This method reloads the current page.
3 func reloadFromOrigin() -> WKNavigation? This method reloads the current page, performing end-to-end revalidation using cache-validating conditionals if possible.
4 func stopLoading(Any?) This method stops loading all the resources of the current page.
5 func load(Data, mimeType: String, characterEncodingName: String, baseURL: URL) -> WKNavigation? This method is used to set the webpage contnts and base url.
6 func loadFileURL(URL, allowingReadAccessTo: URL) -> WKNavigation? This method navigates to the file URL requested on the file system.
7 func setMagnification(CGFloat, centeredAt: CGPoint) This method is used to scale the page content by a specified factor and centers the result on a specified point.
8 func goBack() -> WKNavigation? This method navigates to the back-item present in the back-forward list.
10 func goForward() -> WKNavigation? This method navigates to the forward-item present in the back-forward list.
12 func go(to: WKBackForwardListItem) -> WKNavigation? This method navigates to the specified item from the back-forward list.
13 func load(URLRequest) -> WKNavigation? This method loads the content of the specified URL request.
14 func evaluateJavaScript(String, completionHandler: ((Any?, Error?) -> Void)?) This method is used to evaluate the javascript string.
15 func takeSnapshot(with: WKSnapshotConfiguration?, completionHandler: (UIImage?, Error?) -> Void) This method takes a snapshot of the view's visible viewport.

Example: Creating WKWebView programmatically

Output:

iOS WebView
Next TopicIOS MapView





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA