Class

iOSHTMLViewer


Warning

This item was deprecated in version 2020r2. Please use MobileHTMLViewer as a replacement.

Description

A scrollable HTML viewer control.

Events

Name

Parameters

Returns

Close

Open

Property descriptions


iOSHTMLViewer.AccessibilityHint

AccessibilityHint As Text

The accessibility hint is a longer description that is read aloud when VoiceOver is enabled.

Me.AccessibilityHint = "Click to calculate the value and display the next view."

iOSHTMLViewer.AccessibilityLabel

AccessibilityLabel As Text

The accessibility label of of a control is a short name that is read aloud when VoiceOver is enabled.

Me.AccessibilityLabel = "Calculate the value."

iOSHTMLViewer.Height

Height As Double

The height of the control.

This property is read-only.


iOSHTMLViewer.Left

Left As Double

The left position of the control.

This property is read-only.


iOSHTMLViewer.Name

Name As Text

The name of the control. This can only be set in the Inspector. Use the name to refer to the control.

This property is read-only.


iOSHTMLViewer.Parent

Parent As iOSControl

Indicates the control's parent object, if it has one. If there is no parent, this is Nil.

This property is read-only.


iOSHTMLViewer.Top

Top As Double

The top position of the control.

This property is read-only.


iOSHTMLViewer.Visible

Visible As Boolean

Indicates whether the control is visible.

Make a button invisible:

Button1.Visible = False

iOSHTMLViewer.Width

Width As Double

The width of the control.

This property is read-only.

Method descriptions


iOSHTMLViewer.AddConstraint

AddConstraint(constraint As iOSLayoutConstraint)

Adds a constraint to the control. This constraint is used by child controls that have been added to this control.


iOSHTMLViewer.AddControl

AddControl(child As MobileControl)

Adds a child control to the control.


iOSHTMLViewer.Control

Control(index As Integer) As MobileControl

Gets the child control at the specified index.


iOSHTMLViewer.ControlCount

ControlCount As Integer

The number of child controls in the control.


iOSHTMLViewer.Handle

Handle As Ptr

The handle is used to get a reference to the control for interfacing directly with the iOS API.


iOSHTMLViewer.Invalidate

Invalidate

Marks the control so that it will be redrawn during the next event loop.

Call Invalidate to force a Canvas to redraw itself:

Canvas1.Invalidate

iOSHTMLViewer.LoadURL

LoadURL(url As String)

Displays the specified URL. Be sure to include the appropriate prefix, such as "http://".

To load HTML from a file on the device, pass FolderItem.URLPath to LoadURL.

To load HTML from Text, first save it to a file using TextOutputStream and then load it using the URLPath to the FolderItem.

Display wikipedia:

HTMLViewer1.LoadURL("https://www.wikipedia.org")

To display HTML that is in a file, you can load it by using the URLPath for the file. This example saves HTML to a text file and then loads the file into an HTMLViewer:

Var html As Text = "<body>Hello!</body>"

Var htmlFile As FolderItem = SpecialFolder.Documents.Child("hello.html")
Var output As TextOutputStream
output = TextOutputStream.Create(htmlFile, TextEncoding.UTF8)
output.WriteLine(html)
output.Close

HTMLViewer1.LoadURL(htmlFile.URLPath)

iOSHTMLViewer.RemoveConstraint

RemoveConstraint(constraint As iOSLayoutConstraint)

Removes a constraint from the control.


iOSHTMLViewer.RemoveControl

RemoveControl(child As MobileControl)

Removes the control from the control.


iOSHTMLViewer.SetTintColor

SetTintColor(value As Color)

Changes a control's tint color. This varies by control and for some controls may not do anything. For example, with an MobileTextField this changes the cursor color.

Event descriptions


iOSHTMLViewer.Close

Close

Called when the control is removed from its container, such as a view.


iOSHTMLViewer.Open

Open

Called after the control is created. This is where you typically put initialization code.

Set label text in Open event:

Me.Text = "Hello"

Notes

App transport security

Starting with iOS 9, you have to use secure "https" connections or the page will not display. To continue to connect to non-secure "http" connections that you do not control you'll have to provide a plist with a temporary exception specified for each site you are accessing via http:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>firstsite.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
            <key>secondsite.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
</dict>
</plist>

If you don't know the specific sites, you can request access to everything using a single key:

<key>NSAppTransportSecurity</key>
<dict>
  <!-- Include to allow all connections; avoid if possible -->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

Apple may reject your App Store submission if you app uses these settings without valid reasons.

For more information about this, refer to NSAppTransportSecurity in Apple's docs. .. warning:: Apparently there is a bug in iOS that prevents the use of IP addresses in this plist. So to enable http on your local computer for testing use "localhost" rather than "127.0.0.1" and be sure to use "http://localhost" in your URLs instead of "http://127.0.0.1".

Compatibility

iOS projects on the iOS operating system.

See also

MobileControl parent class; URLConnection class; Using a plist topic