Change text size automatically

I have a list of words that I am displaying on a label. Is there a way to automatically change the font size of the words so that they are optimized for view on the label? For example, if my words are two or three letters long, I want the font to be big, so it fills the label. However, if the words are longer, or if there are a couple of words to be displayed, the font size will need to be smaller so it can all be seen.
Ideas?
Thanks in advance,
Heather

Not exactly what you want, but you may try Ellipsize label extension to restrict the label text within specified number of lines and truncates if it exceeds.

Thanks so much for the input. As you identified, this doesn't seem to be what I am looking for, but I appreciate the info.
Heather

Since it is possible to set the font size in a Label using Blocks ( FontSize Specifies the label’s text’s font size) you possibly can do something by checking the length of the text in the label and use conditional statements to determine what font to use based on the length of characters.

There isn't a magic way to do this. Experiment.

Here is some sample code showing how to get text width in real time.
For your case, you would need to set up a feedback loop (Timer) to adjust your font size.
demo


text_width.aia (2.0 KB)
blocks

How wide is the label, and why does it have to be a specific width ?

You could try something like this:

See Screen2 for sample code:
sample run Screen2


text_width.aia (4.2 KB)

Groovy :wink:

1 Like