setSize

Category:UI Controls

Sets the width and height for the UI element.

Your app sometimes needs to resize UI elements on a screen. All UI elements (button(), textInput(), textLabel(), dropDown(), checkBox(), radioButton(), image()), can be resized. It is usually easier to place UI elements in their initial positions, with initial sizes, using Design mode in App Lab. In Design mode you can also specify font size, font color and background color for UI elements.

Examples

// Three sizes.
image("idSmall", "https://code.org/images/logo.png");
setSize("idSmall", 50, 50);
image("idMedium", "https://code.org/images/logo.png");
image("idLarge", "https://code.org/images/logo.png");
setSize("idLarge", 200, 200);

Syntax

setSize(id, width, height)

Parameters

NameTypeRequired?Description
id string The ID of the UI element to which this event handler applies. Must begin with a letter, contain no spaces, and may contain letters, digits, - and _.
height number The height to set the UI element to, in pixels.
width number The width to set the UI element to, in pixels.

Tips

  • If a UI element is sized larger than the screen only the part that fits in the screen is displayed. The screen default size is 320 pixels wide and 450 pixels high.

Found a bug in the documentation? Let us know at documentation@code.org