UI module: label:SetTextColor does nothing

Hi folks,

I am using the UI module and there some labels. Whenever I want to change the color of the text, it does nothing.
Here is a sample that shows the effect:

--------------------------------------------------------------------------------- ui = require("ui") local mylabel = ui.newLabel{ bounds = { 30, 20, 60, 18 }, text = "energy", font = "Verdana-Bold", textColor = { 0, 200, 0, 255 }, size = 16, align = "left" } local text2 = display.newText( "033", 0, 40, "Verdana-Bold", 12 ) mylabel:setTextColor({255,0,255,255}) text2:setTextColor(255,0,255,255) ---------------------------------------------------------------------------------
The color of text2 gets changed, the color of mylabel not!

Michael Hartlef [import]uid: 5712 topic_id: 781 reply_id: 300781[/import]

Here’s a temporary fix to newLabel function, use setColor function on label to set text color. Andrew


– Label class

function newLabel( params )
local labelText
local size, font, textColor, align

if ( params.bounds ) then
local bounds = params.bounds
local left = bounds[1]
local top = bounds[2]
local width = bounds[3]
local height = bounds[4]

if ( params.size and type(params.size) == “number” ) then size=params.size else size=20 end
if ( params.font ) then font=params.font else font=native.systemFontBold end
if ( params.textColor ) then textColor=params.textColor else textColor={ 255, 255, 255, 255 } end
if ( params.offset and type(params.offset) == “number” ) then offset=params.offset else offset = 0 end
if ( params.align ) then align = params.align else align = “center” end

if ( params.text ) then
labelText = display.newText( params.text, 0, 0, font, size )
labelText:setTextColor( textColor[1], textColor[2], textColor[3], textColor[4] )

if ( align == “left” ) then
labelText.x = left + labelText.stageWidth * 0.5
elseif ( align == “right” ) then
labelText.x = (left + width) - labelText.stageWidth * 0.5
else
labelText.x = ((2 * left) + width) * 0.5
end
end

labelText.y = top + labelText.stageHeight * 0.5

– Public methods
function labelText:setText( newText )
if ( newText ) then
self.text = newText

if ( “left” == align ) then
self.x = left + self.stageWidth / 2
elseif ( “right” == align ) then
self.x = (left + width) - self.stageWidth / 2
else
self.x = ((2 * left) + width) / 2
end
end
end

function labelText:setColor( textColor ) – *** AGRW
if ( textColor and type(textColor) == “table” ) then
self:setTextColor( textColor[1], textColor[2], textColor[3], textColor[4] )
end
end
end

– Return instance
return labelText

end

[import]uid: 3867 topic_id: 781 reply_id: 1602[/import]

Thanks Andrew, will do the change. [import]uid: 5712 topic_id: 781 reply_id: 1604[/import]

(Logged as bug #133) [import]uid: 3 topic_id: 781 reply_id: 2037[/import]