object:resizeHeightToFitFont()

Type Function
Object TextField
Library native.*
Return value none
Revision Release 2024.3703
Keywords resizeHeightToFitFont, native text input
See also object:resizeFontToFitHeight()
native.newTextField()

Overview

Changes the height of the text field to “best fit” the font size that it’s currently using.

Syntax

object:resizeHeightToFitFont()

Example

-- Create the text field
-- When a text field is created, it will auto-size its font to best fit the field height
local textField = native.newTextField( 160, 240, 280, 40 )
textField.text = "Hello World"

-- Change the text field's font size to the system default 
textField.size = nil
-- Resize the text field's height to best fit the font
textField:resizeHeightToFitFont()