WKInterfaceObject
An object that provides information that is common to all interface objects in your watchOS app.
Declaration
class WKInterfaceObjectMentioned in
Overview
Your WatchKit extension uses interface objects to manipulate the visual elements displayed on Apple Watch. Specifically, you use the methods of this class to change the size, alignment, and visibility of those elements. You can also configure the accessibility information displayed through assistive technologies like VoiceOver.
Do not subclass or create instances of this class, or any of its subclasses, 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 in your interface, define a property with the following syntax in your interface controller class:
At runtime, WatchKit creates the appropriate interface objects and assigns them to the outlets in your interface controller.
WatchKit provides one-way communication between the interface objects in your extension and the corresponding interface elements in your watchOS app. You can set the values of an interface object, but you cannot get the current values. If you want to know the current value of an attribute, you must save the value yourself.
Interface Builder Configuration Options
Xcode lets you configure information about your group interface object in your storyboard file. The following table lists the attributes you can configure in your storyboard and their meaning.
Attribute | Description |
|---|---|
Alpha | The opacity of the object. A value of |
Hidden | A checkbox indicating whether the item is hidden initially. You can change the visibility of the item programmatically by calling the Sethidden(_:) method. |
Installed | A checkbox indicating whether the item is installed for the current device. |
Horizontal | The horizontal alignment of the item. Use this attribute to configure the horizontal position of the item relative to its immediate parent. |
Vertical | The vertical alignment of the item. Use this attribute to configure the vertical position of the item relative to its immediate parent. |
Width | The width of the object. Specify a fixed width or set the value of the object to be a percentage of its container’s width. |
Height | The height of the object. Specify a fixed height or set the value of the object to be a percentage of its container’s height. |
Topics
Hiding and Showing an Object
Getting the Property Name
Changing an Object’s Size
setWidth(_:)setHeight(_:)setRelativeWidth(_:withAdjustment:)setRelativeHeight(_:withAdjustment:)sizeToFitWidth()sizeToFitHeight()
Setting an Object’s Alignment
Configuring the Accessibility Attributes
setAccessibilityIdentifier(_:)setAccessibilityLabel(_:)setAccessibilityHint(_:)setAccessibilityValue(_:)setIsAccessibilityElement(_:)setAccessibilityTraits(_:)setAccessibilityImageRegions(_:)