Mobile 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 MobileButton in the Language Reference.


Pressed - Called when the user taps on the button.


Caption - The text that displays in the button.

Enabled - Indicates if the button is enabled and can be tapped or disabled and cannot be tapped.

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

Visible - Indicates whether the button is shown on the layout when the app is running.


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
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.CaptionColor = Color.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 Pressed event handler is called when the button is tapped. You may have code here to display a new screen or perform any type of action. This code in the Pressed event handler of a button displays a new screen:

Var v As New Screen2

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


See Also

MobileButton class