I have a recipe app. I am trying to style the individual words in the Recipe Title.
The recipe titles are pulled from a database and then displayed using the tableView widget.
I want to stye the first word in the title differently from the rest. For example . . .
“Asian Beef Lettuce Wraps”
I want “Asian” bold type and green. “Beef Lettuce Wraps” normal type, black.
I figured out how to separate the first word from the rest of the title (“listRecs[idx].name” is the Recipe Title variable):
local titleLength = string.find(listRecs[idx].name, " ", 1)
local titleFirst = string.sub(listRecs[idx].name, 1, titleLength )
local titleRemain = string.sub(listRecs[idx].name, titleLength )
I thought that would be the hard part. What I can’t get right is putting the title back together.
The obvious way was to use display.newText on each the two pieces of the title. Problem is when I have a lengthy title like “Asian Beef Lettuce Wraps.” It looks like this on screen:
Asian Beef Lettuce
Wraps
See how “Wraps” aligns itself under Beef? Yeah, no bueno. Since Asian is it’s own display.newText, Corona won’t word wrap “Beef Lettuce Wraps” under “Asian.” And the y axis gets all screwy too.
What I want is:
Asian Beef Lettuce
Wraps
My other thought was to take each piece of the title, style it with the bold and color and concatenate the two pieces into one string and then use display.newText. But I couldn’t figure out how to do that.
Anyways, if someone could point me in the right direction it would be appreciated.