Is is possible to change the color of a label on a button widget?

Hi,

I know how to change the label of button (using the widget library) but how to change the color of the label text? Is it even possible?

Thanks a lot for any help.

Mo [import]uid: 100814 topic_id: 30772 reply_id: 330772[/import]

local playBtn = widget.newButton{  
 label = "Play",  
 defaultColor = { 34, 34, 34, 255 },  
 overColor = { 129, 122, 128, 100 },  
 strokeColor = { 164, 198, 57, 255 },  
 strokeWidth = 1,  
 font = "Spliffs",  
 fontSize = 28,  
 yOffset = -14,  
 labelColor = { default={ 102, 255, 0, 255 }, over={ 164, 198, 57} },  
 emboss = true,   
 width = 150, height = 45,  
 id = "playBtn",   
 onRelease = onPlay  
}   

Line 10… [import]uid: 114389 topic_id: 30772 reply_id: 123214[/import]

Oh, thank you Sliky. Actually I was looking for changing the color on the fly after I set it up as you show?

Mo [import]uid: 100814 topic_id: 30772 reply_id: 123217[/import]

BTW I am using the tab widget.
[import]uid: 136344 topic_id: 30772 reply_id: 123297[/import]

EF [import]uid: 136344 topic_id: 30772 reply_id: 123296[/import]

never mind [import]uid: 136344 topic_id: 30772 reply_id: 123299[/import]

any idea how to change the color of the tabs?

I have tried several combinations.
local demoTabs = widget.newTabBar{
top=display.contentHeight-5,
bottomfill={ red },
buttons=tabButtons
}
nothing changes.
Finally got the tabbutton text to change colors.

[import]uid: 136344 topic_id: 30772 reply_id: 123300[/import]

local playBtn = widget.newButton{  
 label = "Play",  
 defaultColor = { 34, 34, 34, 255 },  
 overColor = { 129, 122, 128, 100 },  
 strokeColor = { 164, 198, 57, 255 },  
 strokeWidth = 1,  
 font = "Spliffs",  
 fontSize = 28,  
 yOffset = -14,  
 labelColor = { default={ 102, 255, 0, 255 }, over={ 164, 198, 57} },  
 emboss = true,   
 width = 150, height = 45,  
 id = "playBtn",   
 onRelease = onPlay  
}   

Line 10… [import]uid: 114389 topic_id: 30772 reply_id: 123214[/import]

Oh, thank you Sliky. Actually I was looking for changing the color on the fly after I set it up as you show?

Mo [import]uid: 100814 topic_id: 30772 reply_id: 123217[/import]

BTW I am using the tab widget.
[import]uid: 136344 topic_id: 30772 reply_id: 123297[/import]

EF [import]uid: 136344 topic_id: 30772 reply_id: 123296[/import]

never mind [import]uid: 136344 topic_id: 30772 reply_id: 123299[/import]

any idea how to change the color of the tabs?

I have tried several combinations.
local demoTabs = widget.newTabBar{
top=display.contentHeight-5,
bottomfill={ red },
buttons=tabButtons
}
nothing changes.
Finally got the tabbutton text to change colors.

[import]uid: 136344 topic_id: 30772 reply_id: 123300[/import]

If someone is interested yet, for me the following code is working:

button._view._label._labelColor.default = { 1, 0, 0, 0.5 }

button._view._label:setFillColor( 1, 0, 0, 0.5 )

In the first line, we specify new default label color for our button. I dont know why, but it start working only after we click the button, so in order to cover it, in the second line we immediately set fill color for label to our new(second line works only before button click).

If we want to change over labelColor, we dont need second line.

Im pretty sure its not the best sollution, but didn’t find better.

1 Like

Keep in mind that accessing any internal structure that starts with “_” isn’t safe. We prefix internal variables and structures with an underscore if they are considered “private” variables. These are subject to change at any time, without warning.

I would recommend downloading the widget library from our github repository https://github.com/coronalabs/framework-widget

And build your own setColor method.

Rob

As I said I wasn’t sure about my solution. Your way seems to be better idea and I’m going to give it a try. Thanks for Your warning about variables beginning with underscores :slight_smile:

If someone is interested yet, for me the following code is working:

button._view._label._labelColor.default = { 1, 0, 0, 0.5 }

button._view._label:setFillColor( 1, 0, 0, 0.5 )

In the first line, we specify new default label color for our button. I dont know why, but it start working only after we click the button, so in order to cover it, in the second line we immediately set fill color for label to our new(second line works only before button click).

If we want to change over labelColor, we dont need second line.

Im pretty sure its not the best sollution, but didn’t find better.

Keep in mind that accessing any internal structure that starts with “_” isn’t safe. We prefix internal variables and structures with an underscore if they are considered “private” variables. These are subject to change at any time, without warning.

I would recommend downloading the widget library from our github repository https://github.com/coronalabs/framework-widget

And build your own setColor method.

Rob

1 Like

As I said I wasn’t sure about my solution. Your way seems to be better idea and I’m going to give it a try. Thanks for Your warning about variables beginning with underscores :slight_smile: