类型 布尔值 对象 TextField 库 native.* 修订 版本 2024.3703 关键词 原生文本输入 另请参阅 native.newTextField()
确定文本字段的 object.size 和 object.font 属性使用哪种字体大小单位进行测量。
如果值为 true
,则读取或写入文本字段属性的字体大小使用 Corona 的
如果值为 false
,则读取或写入文本字段属性的字体大小使用平台的原生点系统。在这种情况下,Corona 内容缩放不会应用于字体大小。在 iOS 上,这使用 Apple 的点系统。在 Android 上,这是以 DP 单位设置的
创建文本字段后,此属性的默认值由 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 ) )