loading

iOS: Web View

WebView is an object that can load HTML strings for an in-app browser within an iOS application and display interactive web content. It is a WKWebView instance, which is derived from the UIView class.

				
					class WKWebView : UIView
				
			

As previously noted, the WebView object may be used to load web content into an iOS application. To load web material, we only need to create an instance of a WKWebView object, set it as a view, and send it a request.

WKWebView Properties and Methods

To alter the webview’s behavior, utilize the attributes and methods found in the WKWebView class. We may utilize the goBack() and goForward() methods to allow the user to travel both forward and backward. We may utilize the Boolean values canGoBack and canGoForward to see if the user can travel in a specific direction.

Additionally, WebView turns the phone number into links that, when clicked, take the user to a dialer pad that already has the tapped number entered.

WKWebView Properties

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

WKWebView Methods

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

iOS: Web View

Or copy link

Explore Topic