A button in the user interface of your watchOS app.
- watchOS 2.0+
The content of a button's tappable area is filled with text and an optional background color or image. When tapped by the user, the button calls its associated action method, which you define on the owning interface controller. Use that action method to initiate tasks and update your app’s interface.
Do not subclass or create instances of this class yourself. Instead, define outlets in your interface controller class and connect them to the corresponding objects in your storyboard file. For example, to refer to a button object in your interface, define a property with the following syntax in your interface controller class:
During the initialization of your interface controller, WatchKit creates a new instance of this class and assigns it to your outlet. At that point, you can use the object in your outlet to make changes to the onscreen button.
To respond to taps in the button, declare a method of this form in the interface controller class that manages the button:
You can change the name of your action method to anything you like. In your Xcode storyboard, connect the button’s selector to the custom action method defined in your class.
Interface Builder Configuration Options
Xcode lets you configure information about your button interface object in your storyboard file. Table 1 lists the attributes you can configure in your storyboard and their meaning.
The type of content contained in the button. A button can contain a single text label or a group. For buttons containing a group, you can add text, images, and other objects to the group.
The color to apply to the button’s title.
The font to apply to the button’s title. You can set font information programmatically using the
A checkbox indicating whether the button is enabled and sends events when tapped. You can also configure this value programmatically using the
The background color for the button.