iOS Button
From Xojo Documentation
Contents
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.
Below are commonly used properties and events. For the complete, list refer to iOSButton in the Language Reference.
Events
- Called when the user taps on the button.
Properties
- The text that displays in the button.
- A boolean that indicates if the button is enabled and can be clicked or disabled and cannot be clicked.
- The color of the text that is displayed in the button.
- 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:
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:
You can change the color of the text by simply assigning a new color using either the Inspector or from your code:
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:
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:
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:
See Also
iOSButton class; UserGuide:iOS UI topic