Back

Text

Create Text objects using the CreateText method of the app object:

 txt = app.CreateText( text, width, height, options );

You can use the "Multiline" option to allow multi-line text and the "Left" or "Right" options to align the text. The default is single line centered text.

Use the SetText and GetText functions of the Text object to set and get it's text.

Example - Single line

function OnStart()
{
  lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

  txt = app.CreateText( "Hello" );
  txt.SetTextSize( 22 );
  lay.AddChild( txt );

  app.AddLayout( lay );
}
  Copy   Copy All    Run   

You can change the look of a Text using the SetBackColor and SetTextColor functions on the Text object.

Example - Multi line

function OnStart()
{
  lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

  txt = app.CreateText( "Hello\nWorld", 0.8, 0.2, "Multiline" );
  txt.SetTextSize( 12 );
  txt.SetTextColor( "#ff6666ff" );
  txt.SetBackColor( "#ffffffff" );
  lay.AddChild( txt );

  app.AddLayout( lay );
}
  Copy   Copy All    Run   

You can also set a background image/pattern or background gradient for the Text using the SetBackground and SetBackGradient functions. See Layouts for examples of how to use these functions.


The following methods are avaiable on the Text object:

 SetVisibility( visibility )
 GetVisibility()
 SetPadding( left, top, right, bottom )
 SetMargins( left, top, right, bottom )
 SetBackground( imageFile, options )
 SetBackColor( colorCode )
 SetBackGradient( color1, color2, color3 )
 SetBackGradientRadial( x, y, r, color1, color2, color3 )
 SetPosition( left, top, width, height )
 SetSize( width, height )
 GetWidth()
 GetHeight()
 SetText( text )
 SetHtml( html )
 GetText()
 SetTextColor( colorCode )
 SetTextSize( size )
 GetLineCount()
 GetMaxLines()
 GetLineTop( lineNum )
 GetLineStart( lineNum )
 SetOnTouch( callback )
 SetOnTouchUp( callback )
 SetOnTouchMove( callback )
 SetOnTouchDown( callback )
 SetOnLongTouch( callback )
 SetTouchable( touchable )