Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Position text inside a label (Titanium Mobile)

Is there a way to control the vertical alignment of text inside a label, e.g. say your label is 300px in height, but you want the text to start at 20px from the top edge.

Is there any way to control this?


— asked June 29th 2010 by HOWEST *
  • align
  • ipad
  • iphone
  • label
  • mobile
  • text
  • vertical

3 Answers

  • I noticed there are TEXT_VERTICAL_ALIGNMENT_TOP,.._BOTTOM,… constants in the base Titanium.UI library, but what property can I couple it with to achieve the alignment or is this not possible within a label?

    — answered June 30th 2010 by HOWEST *
  • This worked for me, but it won't cut the text if it is longer (higher) then the height of the View:

    this.infoContainer = Titanium.UI.createView({
        top    : 19,
        left    : 62,
        width    : 238,
        height    : 28
    this.infoLabel = Titanium.UI.createLabel({
        height    : 'auto',
        top    : 0

    Result: Top-Vertical-Align of a text in a two line height element.
    But the label will no longer truncate (and add a trailing '…') the text when the text is longer (higher).

    Any tricks to have top-align and truncate of the text?

    — answered December 9th 2010 by Udo Trappe
    1 Comment
    • The problem is that height:'auto' precludes truncation.

      Here is one idea.

      Add a custom event listener to the label (e.g. refresh) which you can fire immediately after you change the label text.

      Then, in the listener:

      if(this.infoLabel.size.height > 28)
          this.infoLabel.height = 28;
          this.infoLabel.height = 'auto';

      — commented December 9th 2010 by James K
  • I am interested in this, too. Even did not find an example in KitchenSink.

    — answered July 1st 2010 by Jicks Steen
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.