Help with On/Off switch Widget

So I’m trying to utilize this widget but I have some questions about it since I can’t figure it out.

  1. Am I able to adjust the size of this widget? When I switch between different screen sizes on the simulator, it remains the same size and I ideally want to adjust the size accordingly. 

  2. Default for the switch is a blue color when the switch is on, can I somehow change it to green? I’m completely lost on how to do this because all I did was copy paste the code for the widget (without adding images to my main.lua) and somehow it is showing pictures to create the widget! haha, So If I wanted to create my own custom images, I don’t know the sizes of the pictures that are required, etc.

heres a convenient link to the corona doc:

https://docs.coronalabs.com/api/library/widget/newSwitch.html#initialswitchstate-optional

Here’s what I copy/pasted into my main.lua as a test

[lua] local widget = require( “widget” )

– Handle press events for the checkbox

local function onSwitchPress( event )

    local switch = event.target

    print( “Switch with ID '”…switch.id…"’ is on: "…tostring(switch.isOn) )

end

– Create the widget

local onOffSwitch = widget.newSwitch(

    {

        x = display.viewableContentWidth/2,      — x location

        y = display.viewableContentHeight/2,       — y location

        style = “onOff”,

        id = “onOffSwitch”,

        onPress = onSwitchPress

    }

)

onOffSwitch.anchorX = 0   – doesn’t seem to do anything

onOffSwitch.anchorX = 0

 [/lua]

Thanks for any help!!

  1. It say’s in the gotcha’s that you cannot change the width or height

that being said you can ajust the xScale and yScale 

local widget = require( "widget" ) -- Handle press events for the checkbox local function onSwitchPress( event ) local switch = event.target print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) ) end -- Create the widget local onOffSwitch = widget.newSwitch( { x = display.viewableContentWidth/2, --- x location y = display.viewableContentHeight/2, --- y location style = "onOff", id = "onOffSwitch", onPress = onSwitchPress } ) onOffSwitch.xScale, onOffSwitch.yScale = 2, 2

Note: This could make the image blurry 

2.The button is an image sheet, width and height are up to you. I ripped the (some what hidden) demo off the corona docs

It is attached bellow

Adding on to what Scott said. You can skin the widget however you like using your own imageSheet, this includes the size. The created on/off switch (using your or our imageSheet) will be a fixed size relative to the content area you defined in your config.lua. In other words, if you have your config.lua setup up for 320x480 (which is recommended for people using widgets) then on a phone it will be one size, on a tablet it will be larger since we take the same screen size and scale it to the device.

However if you are using “adaptive” as a scale in your config.lua, we try to make the widgets the same size on a phone or a tablet. But if you’re using “letterbox” or “zoomEven”, it should be relative to the defined content area.

Rob

  1. It say’s in the gotcha’s that you cannot change the width or height

that being said you can ajust the xScale and yScale 

local widget = require( "widget" ) -- Handle press events for the checkbox local function onSwitchPress( event ) local switch = event.target print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) ) end -- Create the widget local onOffSwitch = widget.newSwitch( { x = display.viewableContentWidth/2, --- x location y = display.viewableContentHeight/2, --- y location style = "onOff", id = "onOffSwitch", onPress = onSwitchPress } ) onOffSwitch.xScale, onOffSwitch.yScale = 2, 2

Note: This could make the image blurry 

2.The button is an image sheet, width and height are up to you. I ripped the (some what hidden) demo off the corona docs

It is attached bellow

Adding on to what Scott said. You can skin the widget however you like using your own imageSheet, this includes the size. The created on/off switch (using your or our imageSheet) will be a fixed size relative to the content area you defined in your config.lua. In other words, if you have your config.lua setup up for 320x480 (which is recommended for people using widgets) then on a phone it will be one size, on a tablet it will be larger since we take the same screen size and scale it to the device.

However if you are using “adaptive” as a scale in your config.lua, we try to make the widgets the same size on a phone or a tablet. But if you’re using “letterbox” or “zoomEven”, it should be relative to the defined content area.

Rob