UserGuide

iOS Button

From Xojo Documentation

Buttons are tapped by the user to evoke an action. A button is a native iOS control and as such, does not have a border unless you have turned on Button Shapes in iOS Accessibility settings. To add a Button to your layout, drag it from the Library to a position on the Layout.

The Set Default Value feature can be used to quickly change the button Caption.

iOS Button Library Icon

Below are commonly used properties and events. For the complete, list refer to iOSButton in the Language Reference.

Events

Action

Called when the user taps on the button.

Properties

Caption

The text that displays in the button.

Enabled

A boolean that indicates if the button is enabled and can be clicked or disabled and cannot be clicked.

TextColor

The color of the text that is displayed in the button.

Visible

A boolean that indicates whether the button is shown on the layout when the app is running.

Usage

Generally you will set the Caption for the button using the Inspector, but you can also set or change the Caption in your code by just assigning it a new value:

MyButton.Caption = "Add Task"

Enabling and disabling a button can be useful when the button does not because useful unless some data is provided. For example, you may require that a name be entered in a Text Field before a Continue button is enabled. This code in a Text Field TextChange event handler enables or disables a button depending on whether the field has text:

If Me.Text = "" Then
MyButton.Enabled = False
Else
MyButton.Enabled = True
End If

You can change the color of the text by simply assigning a new color using either the Inspector or from your code:

MyButton.TextColor = &cff0000 // Red

You can use the Visible property to show or hide the button. For example, perhaps you only want to show the button if a row in a table is selected. This code in the Action event handler for a table makes a button visible:

MyButton.Visible = True

The Action event handler is called when the button is clicked. You may have code here to display a new view or perform any type of action. This code in the Action event handler of a button displays a new view:

Dim v As New View2
Self.PushTo(v)

If your code can be triggered by multiple UI actions, put the code in a method and then call the method from the Action event handlers:

MyActionMethod

See Also

iOSButton class; UserGuide:iOS UI topic