Displaying Single and Multiline Message label using Corona SDK

Introduction: On every other application we need to use label in order to display custom message to the screen. I am going to demonstrate in this blog how can we add a single line and also multi line label to a screen using corona SDK.

Description: Corona SDK actually provides a framework using which we can make cross-platform mobile application like app for IOS and Android. Its provides several API libraries. One of those API is ‘display’ which have a function called newtext() using which we can display a label to any screen.

So let’s start here. We will have a screen where will display a single line label and one multiline label.



-- Hide status bar from the beginning
display.setStatusBar( display.HiddenStatusBar )

-- Assign default background color to all the pages
display.setDefault( 'background', 0, 0, 255 );

On above code block we have hid the status bar and defined a background color for the screen which will be applied throughout the application.

-- Define single line label
local singleLineLabel = display.newText( "Single line label", 150, 100, native.systemFont, 40 )

-- Define text color
singleLineLabel:setTextColor( 0, 0, 255 )

On above code block I have defined a local variable where I have assigned our single line custom message label. To display text content corona has library called ‘display’ which have function newText to do the same. I have passed various parameters to the function ‘newText’ which I have described below.
“Single line label”: string that we want to show.

150: left position of the label
100: top position of the label.
native.systemFont : font style
40 : font size.

‘setTextColor’ function used to set the text color which is RGB format.

On the same way we will called the display.newText function to display multiline label using additional parameter to it.

-- Define multiline message label
local multilineLabel = display.newText( "This is a multiline label message. To make a multiline label we just need to assign height and width of the label.", 15, 250, 300, 400,  native.systemFont, 40 )

multilineLabel:setTextColor( 0, 0, 255 )

On above code block you can see that I have assigned long message the label. Then the next two parameters (15 and 250) describe the left and top position respectively. Then next two parameters (300 and 400) mentioned width and height of the label which exactly makes the label multiline.

Summary : So here we have seen how easily using display API in corona we can show a single line label to a screen and also by adding width and height of that label only we can make them as multiline label.

Written ByRaju Mahato, Software Developer, Mindfire Solutions

One thought on “Displaying Single and Multiline Message label using Corona SDK

  1. Pingback: Displaying single and multiline message label using corona sdk. | Cross Platform Mobile App Architecture

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s