PadCodedocs

Switch

An on/off switch.

Switch selected on the canvas, with its settings in the Inspector.

In the Library: Components → Controls

#When to use it

Use a Switch for one on/off choice: notifications, dark mode, "show details". It keeps a True / False variable up to date. To pick one of several choices, use a Picker; for a number, a Slider or a Stepper.

#How to use it

  1. Add a Switch. PadCode makes a True / False variable for it, isOn (or isOn2… if that's taken), that starts on.
  2. Type the words beside it in Title.
  3. To use a variable of your own, pick it in Is On (or in the Data tab).
  4. Use the variable anywhere: type its name in another view's Show when, or in a formula.

#Example

A recipe screen has a Switch titled Show nutrition, linked to a True / False variable showNutrition. A Column of nutrition facts below it has Show when set to showNutrition, so it appears only while the switch is on.

#Good to know

  • The switch doesn't flip on the canvas: tapping selects it. Try it in Preview. To change whether it starts on or off, change its variable's value in Data & Logic.
  • Control → Style → Button turns it into a button that stays highlighted while it's on.
  • Text + Icon in Made of adds an icon before the words. Text + Image one of your own pictures (from Assets).
  • To run steps each time it's flipped, add the When a Value Changes modifier and pick its variable.

#Add it

In the Library's Components tab, find Switch under Controls (or search for it) and either:

  • Tap it. It goes inside the selected container, at the end; right after the selected view, if that isn't a container; or at the bottom of the screen when nothing is selected.
  • Drag it onto the canvas, to exactly where you want it. A line shows where it will land.

#Made of

The Made of menu, at the top of its settings, picks which pieces it has. Switching keeps the settings the versions share.

  • Text (where it starts)
  • Custom content
  • Text + Image
  • Text + Icon

#Settings

In the Inspector's Style tab, top to bottom. Tap ⓘ next to a setting in the app for the same help.

#Switch

SettingWhat it doesHow you set itStarts as
TitleThe words shown on it. Put a variable in braces to show its value: Hello, {name}!Text box, or ⚡︎ to link a variableNotifications
Is OnThe True / False variable this switch turns on and off.Menu: pick a variable, or New Value to make oneisOn, a variable PadCode makes for it

#Text

Shared with other views: see Text.

SettingWhat it doesHow you set itStarts as
FontThe text style: Title, Headline, Body and so on. They grow with the size people set for text on their iPad.Menu: Large Title, Title, Title2, Title3, Headline, Subheadline, Body, Callout, Caption, Caption2, Footnote, CustomDefault
TypefaceThe letters' design: System (San Francisco), any font on the iPad, or a font file you add to this app.Opens a pickerSystem
WeightHow thick the letters are, from Light to Black.Menu: Default, Ultra Light, Thin, Light, Regular, Medium, Semibold, Bold, Heavy, BlackDefault
DesignThe letter shapes: Default, Rounded, Serif or Monospaced (every letter the same width).Menu: Default, Rounded, Serif, MonospacedDefault
ColorThe color of the text.Color menu, or the color wheelNone
AlignHow the lines of text line up: left, center or right.Buttons: Left, Center, Right—
Max linesHow many lines the text can use before it ends with “…”. Empty means no limit.Text boxNo limit
Letter spacingExtra space between letters, in points. A negative number squeezes them together.Text box0
CaseShows the text as typed, in UPPERCASE or in lowercase. The text itself doesn't change.Menu: As typed, Uppercase, LowercaseAs typed
Bold · Italic · Underline · StrikethroughButtons that turn bold, italic, underline and strikethrough on and off for the text.Four buttons, each on or off—

#Size & spacing

Shared with other views: see Size & spacing.

SettingWhat it doesHow you set itStarts as
PaddingEmpty space around the view, inside its background. One number for every side, like 16.Text boxNone
SidesPadding for one side only: T is the top, L the left, B the bottom, R the right.Text box—
WidthAuto fits the content. Fill takes all the room it can. Fixed sets an exact size in points.Menu: Auto, Fill, Fixed (then a number)Auto
HeightAuto fits the content. Fill takes all the room it can. Fixed sets an exact size in points.Menu: Auto, Fill, Fixed (then a number)Auto
OffsetNudges the view X points right and Y points down, without moving anything around it. Negative numbers go left and up.Text box—

#Look

Shared with other views: see Look.

SettingWhat it doesHow you set itStarts as
BackgroundA color behind the view. Add Padding so it doesn't hug the content.Color menu, or the color wheelNone
CornersRounds the background's corners, in points. 12 is gently rounded; a big number makes a pill.Text box0
BorderA line around the view, in the color you pick.Color menu, or the color wheelNone
ShadowA soft shadow under the view, so it looks raised.SwitchOff
OpacityHow solid the view is. All the way right is solid; all the way left is invisible.Slider100%
Liquid GlassApple's glass look: the view blurs and reflects what's behind it.SwitchOff

#Control

Shared with other views: see Control.

SettingWhat it doesHow you set itStarts as
StyleThe look iOS gives this control, like a filled or a plain button. Automatic lets iOS choose.Menu: Automatic, Button, SwitchAutomatic
AccentThe color of the control's active parts, like a switch when it's on.Color menu, or the color wheelNone
SizeHow big the control is: small, regular, large or extra large.Menu: Mini, Small, Regular, Large, Extra LargeRegular

#Show & enable

Closed at first. Show when shows the view only while a condition is true; Disabled grays it out. See Show & enable.

#All modifiers

Closed at first. Lists the modifiers on this view, in order, and adds more. It starts with none. See Modifiers.

Every setting of the Switch, top to bottom.

#Data

The Inspector's Data tab shows the variables this view reads or changes. Pick another variable from the menu, or make one.

SettingWhat it doesStarts as
Is OnThe True / False variable this switch turns on and off.isOn, a variable PadCode makes for it
The Switch's Data tab.

#See also