WebView
A web view loads and displays rich web content, such as embedded HTML and websites, directly within your app. Mail uses a web view, for example, to show HTML content in messages.
Best practices
- Enable forward and back navigation when appropriate. Web views support forward and back navigation, but this behavior is disabled by default. If people will use your web view to visit multiple pages, enable forward and back navigation, and provide corresponding controls to initiate these features.
- Avoid using a web view to build a web browser. Using a web view to let people briefly access a website without leaving the context of your app is fine, but Safari is the primary way people browse the web on iOS. Attempting to replicate the functionality of Safari in your app is unnecessary and discouraged.
How to use
- Drop a
WebView
control from the object panel to aWindow
- Use the
WebView Inspector
to customize its properties likeURL
, andAllows Link Preview
If you need to write code for WebView:
- Open the
Code Editor
- Select the
DidFinish
item inside theEvents
area and write your custom code in theCode Editor
The inspector where the WebView
class can be configured.
Example
- Drop a
Button
control from the object panel to aWindow
- Open the
Code Editor
- Select the
Action
item inside theEvents
area and write your custom code in theCode Editor
WebView1.url = "https://www.creolabs.com"
Most important properties
Several UI aspects can be configured in the WebView
class but the url
, allowsBackForwardNavigationGestures
, and allowsLinkPreview
are the most commons to be configured.
url
: Navigates to a requested URL.allowsBackForwardNavigationGestures
: A Boolean value indicating whether horizontal swipe gestures will trigger back-forward list navigations.allowsLinkPreview
: A Boolean value that determines whether pressing on a link displays a preview of the destination for the link. In iOS this property is available on devices that support 3D Touch. Default value is false in iOS.
References
WebView class reference contains a complete list of properties and methods that can be used to customize a WebView
object.