WidgetStack
Stack element shown in widget.
Shows a stack in the widget.
Properties
Section titled “Properties”backgroundColor
Section titled “backgroundColor”Background color of the widget.
backgroundColor: ColorbackgroundGradient
Section titled “backgroundGradient”Background gradient.
backgroundGradient: LinearGradientbackgroundImage
Section titled “backgroundImage”Background image.
backgroundImage: ImageborderColor
Section titled “borderColor”Border color.
borderColor: ColorColor of the border around the stack. Defaults to black.
borderWidth
Section titled “borderWidth”Border width.
borderWidth: numberWidth of the border around the stack. Defaults to 0.
cornerRadius
Section titled “cornerRadius”Radius of the corners.
cornerRadius: numberRadius of the rounded corners. Defaults to 0.
Size of the stack.
size: SizeSpecifies the size of the stack when shown in a widget. When a dimension is set to zero or less, the widget will automatically decide a length for that dimension. Both dimensions default to 0.
spacing
Section titled “spacing”Spacing between elements.
spacing: numberSpecifies the spacing between elements in the stack. You can also use the addSpacer() function on the widget to add spacing between elements. Defaults to 0.
URL to open.
url: stringThe URL will be opened when the text is tapped. This is only supported in medium and large widgets. Small widgets can only have a single tap target, which is specified by the url on the widget.
Methods
Section titled “Methods”
addDate(date)
Section titled “addDate(date)”Add date to the widget.
addDate(date: Date): WidgetDateAdds a date element to the widget. Use the properties on the returned element to style the date.
Parameters
Section titled “Parameters”date Date
Return value
Section titled “Return value”WidgetDate
Date element.
addImage(image)
Section titled “addImage(image)”Add image to the stack.
addImage(image: Image): WidgetImageAdds an image element to the stack. Use the properties on the returned element to style the image.
Parameters
Section titled “Parameters”image Image
Return value
Section titled “Return value”WidgetImage
Image element.
addSpacer(length)
Section titled “addSpacer(length)”Add spacer.
addSpacer(length: number): WidgetSpacerAdds a spacer to the stack. This can be used to offset the content horizontally in the stack.
Parameters
Section titled “Parameters”length number
Length of the spacer. Pass null to create a spacer with a flexible length.
Return value
Section titled “Return value”WidgetSpacer
Spacer element.
addStack()
Section titled “addStack()”Add stack.
addStack(): WidgetStackAdds a stack to the widget. Stacks layout elements horizontally by default.
Return value
Section titled “Return value”WidgetStack
Stack element.
addProgress(value, options)
Section titled “addProgress(value, options)”Add a progress indicator to the widget.
addProgress(value: number, options: dictionary?): WidgetStackAdds a progress indicator with a value from 0 to 100. Values outside that range are clamped. Use the returned stack to size the indicator or add content centered on top of it.
Parameters
Section titled “Parameters”value number
Progress from 0 to 100.
options dictionary?
Optional dictionary with style (“circular” or “linear”), progressColor, trackColor, and thickness in points. The default style is circular. Thickness sets the ring stroke or the initial height of a linear bar.
Return value
Section titled “Return value”WidgetStack
A stack sized to 40 by 40 points for a ring or 120 points wide for a bar.
addButton(title, options)
Section titled “addButton(title, options)”Add a button that runs a widget action.
addButton(title: string, options: {[key: string]: string})Tapping the button runs the configured script in the widget and reloads the widget. Read args.widgetAction.id to handle the action. Interactive controls require iOS or iPadOS 17 or later and a widget family that supports them. Interactive controls take precedence over a URL on the containing stack.
Parameters
Section titled “Parameters”title string
The label shown on the control.
options {[key: string]: string}
A dictionary with a non-empty string id.
addRefreshButton(title)
Section titled “addRefreshButton(title)”Add a button that refreshes the widget.
addRefreshButton(title: string)Tapping the button reloads the widget and runs its normal render. The render receives no widget action. Interactive controls require iOS or iPadOS 17 or later and a widget family that supports them. Interactive controls take precedence over a URL on the containing stack.
Parameters
Section titled “Parameters”title string
The label shown on the control.
addToggle(title, isOn, options)
Section titled “addToggle(title, isOn, options)”Add a toggle that runs a widget action.
addToggle(title: string, isOn: boolean, options: {[key: string]: string})Read args.widgetAction.isOn to get the requested state. Save the state before the script finishes and read it when rendering the widget again. Interactive controls require iOS or iPadOS 17 or later and a widget family that supports them. Interactive controls take precedence over a URL on the containing stack.
Parameters
Section titled “Parameters”title string
The label shown on the control.
isOn boolean
The current saved state of the toggle.
options {[key: string]: string}
A dictionary with a non-empty string id.
setAction(title, options)
Section titled “setAction(title, options)”Run a widget action when the stack is tapped.
setAction(title: string?, options: dictionary?)Uses the stack contents as the action’s appearance on iOS or iPadOS 17 or later. Controls inside the stack take precedence over a stack action.
Parameters
Section titled “Parameters”title string?
Accessibility label, or null to clear the action.
options dictionary?
A dictionary with a non-empty string id.
addText(text)
Section titled “addText(text)”Add text to the stack.
addText(text: string): WidgetTextAdds a text element to the stack. Use the properties on the returned element to style the text.
Parameters
Section titled “Parameters”text string
Return value
Section titled “Return value”WidgetText
Text element.
bottomAlignContent()
Section titled “bottomAlignContent()”Bottom aligns the content.
bottomAlignContent()Specifies that content should be bottom aligned.
centerAlignContent()
Section titled “centerAlignContent()”Center aligns the content.
centerAlignContent()Specifies that content should be center aligned.
layoutHorizontally()
Section titled “layoutHorizontally()”Layout elements horizontally.
layoutHorizontally()Specifies that the stack should layout elements horizontally. This is the default.
layoutVertically()
Section titled “layoutVertically()”Layout elements vertically.
layoutVertically()Specifies that the stack should layout elements vertically.
setPadding(top, leading, bottom, trailing)
Section titled “setPadding(top, leading, bottom, trailing)”Set padding.
setPadding(top: number, leading: number, bottom: number, trailing: number)Sets the padding on each side of the stack.
Parameters
Section titled “Parameters”top number
Padding on the top edge.
leading number
Padding on the leading edge.
bottom number
Padding on the bottom edge.
trailing number
Padding on the trailing edge.
topAlignContent()
Section titled “topAlignContent()”Top aligns the content.
topAlignContent()Specifies that content should be top aligned. This is the default.
useDefaultPadding()
Section titled “useDefaultPadding()”Use the default padding.
useDefaultPadding()Configure the stack to use the default padding. Any padding previously defined with setPadding() will be discarded.