object.isFontSizeScaled

类型 布尔值
对象 TextField
native.*
修订 版本 2024.3703
关键词 原生文本输入
另请参阅 native.newTextField()

概述

确定文本字段的 object.sizeobject.font 属性使用哪种字体大小单位进行测量。

如果值为 true,则读取或写入文本字段属性的字体大小使用 Corona 的内容缩放点系统。这与提供给 display.newText() 函数的字体大小相匹配。

如果值为 false,则读取或写入文本字段属性的字体大小使用平台的原生点系统。在这种情况下,Corona 内容缩放不会应用于字体大小。在 iOS 上,这使用 Apple 的点系统。在 Android 上,这是以 DP 单位设置的(设备无关像素)。这是构建版本 #2518 之前的 Corona 默认设置。

创建文本字段后,此属性的默认值由 display.setDefault()"isNativeTextFieldFontSizeScaled" 键确定,默认情况下该键为 true

示例

-- Create a text object
local textSettings =
{
    text = "This is my text label.",
    x = display.contentCenterX,
    y = 100,
    width = display.contentWidth - 20,
    font = native.systemFont,
    fontSize = 20,
}
local textLabel = display.newText( textSettings )

-- Create a native text field using the same font size as the above text object
local textField = native.newTextField( display.contentCenterX, 140, display.contentWidth-20, 40 )
textField.isFontSizeScaled = true  -- Make the field use the same font units as the text object
textField.size = textLabel.size
textField:resizeHeightToFitFont()

-- Print the text field's font size measured in Corona's content-scaled units
print( "Text Field Font Size (Corona Units) = " .. tostring( textField.size ) )

-- Print the text field's font size measured in the platform's native units
textField.isFontSizeScaled = false
print( "Text Field Font Size (Native Units) = " .. tostring( textField.size ) )