object:resizeFontToFitHeight()

类型 函数
对象 文本字段
native.*
返回值
版本 版本 2024.3703
关键字 根据高度调整字体大小、原生文本输入
另请参阅 object:resizeHeightToFitFont()
native.newTextField()

概述

将字体大小更改为文本字段当前高度的“最合适”大小。通过 native.newTextField() 函数首次创建文本字段时,将自动发生此操作。

语法

object:resizeFontToFitHeight()

示例

-- 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 height of the text field
textField.height = 60
-- Resize the font to best fit the text field's new height
textField:resizeFontToFitHeight()