UI Components
Switch
UI component for toggling state on or off.
<Switch>
is a UI component that lets users toggle between two states.
xml
<Switchchecked="true" />
html
<Switchchecked="true" />
tsx
<switch
checked={switchValue}
onCheckedChange={(args) => {
setSwitchValue(args.value)
}}
></switch>
tsx
<switch
on:checkedChange={handleChange}
checked={switchValue()}
></switch>
svelte
<switchbind:checked={switchValue}/>
vue
<Switchv-model="switchValue" />
Examples β
Styling a Switch β
xml
<Switchchecked="true"
color="#BFCDAC"
backgroundColor="green"
offBackgroundColor="#DC493D"
/>
Props β
checked β
ts
checked: boolean
Gets or sets the state switch.
Defaults to false
.
offBackgroundColor β
ts
offBackgroundColor: Color
Gets or sets the off-state background color.
See Color.
...Inherited β
For additional inherited properties, refer to the API Reference.
Events β
checkedChange β
ts
on('checkedChange', (args:PropertyChangeData) => {
constswitch= args.object asSwitch
console.log('Switch checked:', args.value)
})
See PropertyChangeData.
Native component β
- Android:
android.widget.Switch
- iOS:
UISwitch