object.size

Type Number
Object TextField
Library native.*
Revision Release 2024.3703
Keywords text size, native text input
See also native.newTextField()

Overview

Gets or sets the native text field’s font size.

Setting this property to nil or 0 will make the text field use the system’s default font size.

It is recommended that you call object:resizeHeightToFitFont() when changing the font size, because the default font size can vary considerably between devices. The advantage of this approach is that the native text field and its font size will be consistent when compared to other native apps on the same device.

Gotchas

The font size read or written to this property may be either in Corona’s content-scaled points or the platform’s native points. You can determine which font size units are currently being used by querying the text field’s object.isFontSizeScaled property.

By default, the font size is measured in Corona’s content-scaled point system, just like display.newText(), but the default can be changed via the "isNativeTextFieldFontSizeScaled" key of display.setDefault().

Example

-- Create a native text field
local textField = native.newTextField( 50, 100, 100, 35 )
textField.align = "center"

-- Change the text field's size property
textField.size = 32
-- Resize the text field height to fit the font
textField:resizeHeightToFitFont()

textField:setTextColor( 1, 0.5, 0 )
textField.text = "Hello World!"