Dear Corona community,
my native.textfield has a fixed width and I’d like to shrink the fontsize according to user inputlength so that userinput is always visible and not cropped on x-axis. Basically I’m looking for a :resizeFontToFitWidth() solution.
This is how I detect the width of the input:
userInput = native.newTextField( … )
userInput:resizeFontToFitHeight()
invisibleText = display.newText("", 0,0, native.systemFontBold, userInput.size)
So, I have a newText object with an empty string that has the same fontsize as my native.newTextField.
Now, within the “editing” event.phase of the native.newTextField, I do the following:
invisibleText.text = event.text
inputWidth = invisibleText.width
So, I copy the user’s input into my invisible text and get it’s width from there. That works, the only question is: Isn’t there a simpler solution? To me it seems that this is way too complicated, but I couldnt figure out any other way to achieve this.
Thanks for your help