Type Function Library widget.* Return value none Revision Release 2022.3683 Keywords widget, switch, radio, on-off, checkbox, SwitchWidget, setState See also widget.newSwitch() SwitchWidget
Used to programatically set the state of a SwitchWidget. This also changes the state of the switch visually.
object:setState( options )
This function takes a single argument, options
, which is a table that accepts the following parameters:
Boolean. Sets the switch to either on (true
) or off (false
).
Boolean. Applies only to switches with style
of "onOff"
. If set to true
, the switch will visually animate its state change.
Listener. A callback function to be called when the switch has changed state.
-- Create a default on/off switch local onOffSwitch = widget.newSwitch { left = 100, top = 300, initialSwitchState = true } local function changeComplete() print( "Switch change complete!" ) end -- Set the on/off switch to off onOffSwitch:setState( { isOn=false, isAnimated=true, onComplete=changeComplete } )