How set font size in native.newTextField

If a newTextField is set as such:

inputField = native.newTextField( tX, tY, tWidth, tHeight ) – where the parameters are set according to the size of the device

How to best set a font size which will fit in that field just right? I’ve looked at object.isFontSizeScaled= true  that appears to require a font size to be declared first. If so, is there a common formula for working out font size according to the resulting tHeight? I was hoping for a setting to just make this easy. Or am I not understanding object.isFontSizeScaled according to the docs?

Thanks.

Hi @kilopop,

Have you read the tutorial that outlines the most recent updates to native field sizing?

https://coronalabs.com/blog/2014/12/16/tutorial-new-native-text-input-features/

I would suggest you use this tutorial as a guideline, and forget all of that previous “tHeight” tinkering and workaround stuff. These new functions will serve your needs much better.

Best regards,

Brent

Hi Brent,

Thanks, yeah did see that tut and looked at docs. As object.isFontSizeScaled is set to default, I take it all you need to do is create the newTextField and the text will just scale to fit? I haven’t set a font name so I’m guessing it will default to system?

The newTextField parameters such as tHight is still required because the size and position of that field are set according to the device screen size.

Here’s the code:

        inputField = native.newTextField( tX, tY, tWidth, tHeight )
        inputField.x, inputField.y = tX, tY
        inputField.inputType = type – passed in e.g “number”, “email”
        inputField:addEventListener( “userInput”, action.fieldHandler)
        inputField.align = “center”

Currently this works fine in the simulator and fine on device for the iPad but the iPhone 5 shows tiny tiny text in that newTextField.

Hi @kilopop,

Well, it’s probably not quite that simple (one line). :slight_smile: Please see the documentation for a list of the various functions and properties which you can use to control the sizing of input fields and the text within them. The tutorial should cover this as well, so I’m not sure where it’s going awry for you.

http://docs.coronalabs.com/daily/api/type/TextField/index.html

Best regards,

Brent

Hi @kilopop,

Have you read the tutorial that outlines the most recent updates to native field sizing?

https://coronalabs.com/blog/2014/12/16/tutorial-new-native-text-input-features/

I would suggest you use this tutorial as a guideline, and forget all of that previous “tHeight” tinkering and workaround stuff. These new functions will serve your needs much better.

Best regards,

Brent

Hi Brent,

Thanks, yeah did see that tut and looked at docs. As object.isFontSizeScaled is set to default, I take it all you need to do is create the newTextField and the text will just scale to fit? I haven’t set a font name so I’m guessing it will default to system?

The newTextField parameters such as tHight is still required because the size and position of that field are set according to the device screen size.

Here’s the code:

        inputField = native.newTextField( tX, tY, tWidth, tHeight )
        inputField.x, inputField.y = tX, tY
        inputField.inputType = type – passed in e.g “number”, “email”
        inputField:addEventListener( “userInput”, action.fieldHandler)
        inputField.align = “center”

Currently this works fine in the simulator and fine on device for the iPad but the iPhone 5 shows tiny tiny text in that newTextField.

Hi @kilopop,

Well, it’s probably not quite that simple (one line). :slight_smile: Please see the documentation for a list of the various functions and properties which you can use to control the sizing of input fields and the text within them. The tutorial should cover this as well, so I’m not sure where it’s going awry for you.

http://docs.coronalabs.com/daily/api/type/TextField/index.html

Best regards,

Brent