Change button's font size

Hello everyone,

I have a quite simple (stupid ?) question : I can’t find a way to change a button’s label “fontSize” property. I tried changing button._view._fontSize, but the displayed result doesn’t change, event after changing the text via “setLabel”.

Do I really have to recreate a button while destroying the previous one ? Changing some text’s size seems to be something quite simple, so having to destroy my widget and re-creating for that doesn’t sound right to me.

Hi @corona7219,

The trick is to access the actual text object part of the button, then change its .size property, as follows:

[lua]

myButton._view._label.size = 40

[/lua]

Hope this helps,

Brent

Great info Brent! Anyway to do the same with the label color? I have a fire button that I need to turn the label (fire) when the gun is out of ammo! Thanks again. Mo

Hi Mo,

For those who want to go deeper into widgets, and know Lua well enough to do so, you can “unpack” the various tables and access different parameters. We’ve already given developers “hooks” into many of the most common things, but for non-common cases, you can access various parameters as you see fit.

Brent

Thanks Brent! Mo

Hi @corona7219,

The trick is to access the actual text object part of the button, then change its .size property, as follows:

[lua]

myButton._view._label.size = 40

[/lua]

Hope this helps,

Brent

Great info Brent! Anyway to do the same with the label color? I have a fire button that I need to turn the label (fire) when the gun is out of ammo! Thanks again. Mo

Hi Mo,

For those who want to go deeper into widgets, and know Lua well enough to do so, you can “unpack” the various tables and access different parameters. We’ve already given developers “hooks” into many of the most common things, but for non-common cases, you can access various parameters as you see fit.

Brent

Thanks Brent! Mo

I am trying to use the 

\_label

hook to access the size property of my button label, however, I can’t access it: 

attempt to index field 'label' (a nil value)

Could this have something to do with the fact, I am “storing” my buttons in a table?

langague\_buttons[j] = widget.newButton { width = display.contentWidth-200, height = spacing, --defaultFile = "images/selection-screen/film-button.png", --overFile = "images/selection-screen/film-button.png", label = languages[j], font = "Arial Black", fontSize = 50, labelColor = { default = { 255, 255, 255, 1.0 }, over = { 255, 255, 255 , 0.8} }, onEvent = handleChangeLanguageEvent, textOnly = true, id = j }

Hi @ktamiola,

Can you show the full line of code where you’re trying to access that value?

I am trying to use the 

\_label

hook to access the size property of my button label, however, I can’t access it: 

attempt to index field 'label' (a nil value)

Could this have something to do with the fact, I am “storing” my buttons in a table?

langague\_buttons[j] = widget.newButton { width = display.contentWidth-200, height = spacing, --defaultFile = "images/selection-screen/film-button.png", --overFile = "images/selection-screen/film-button.png", label = languages[j], font = "Arial Black", fontSize = 50, labelColor = { default = { 255, 255, 255, 1.0 }, over = { 255, 255, 255 , 0.8} }, onEvent = handleChangeLanguageEvent, textOnly = true, id = j }

Hi @ktamiola,

Can you show the full line of code where you’re trying to access that value?