Titanium Community Questions & Answer Archive

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

Get label height when height property is auto

I'm trying to get the current height of a label. This label got the 'auto' height property when I create it. I need to get the new height after changing for a bigger font. The only property I can get is 'auto', there's no way I can get the height in pixel.
I tried various solution like retrieving the size of the label but it doesn't work.
When auto the size I get is 0.

— asked March 31st 2010 by michel perrin
  • getter
  • label
  • setter
  • zoom

8 Answers

  • I think label.size.height should work for you.

    — answered September 29th 2011 by Phil Sweeney
    • for my iphone app also it is not working

      — commented July 12th 2012 by srikanth pola
    • Here my code for iphone

      var loginLabel = Ti.UI.createLabel({

      text:'tesiting again',



      — commented July 12th 2012 by srikanth pola
  • I think if you specify the width of label,then the label.height can works well.

    var label = Ti.UI.createLabel({
        height: 'auto',
        width: 280
    label.height //this will get the height according to the text of label
    — answered December 14th 2010 by Sam Yang
    • Thanks, this solution works like a charm for iOS.

      But when running this example in Android, label.height returns 'auto' and label.size.height returns 0

      — commented November 30th 2011 by Christian Garcia
    • I'm not sure, but I think timing comes into play in terms of whether the auto height/width has actually been determined yet. I've had some luck wrapping the code in a setTimeout().

          var h = label.size.height;
          // Use h here for what you need

      — commented November 30th 2011 by Phil Sweeney
    • My guess is you're adding the label before opening the window, and then 200ms later the window has been opened, which made the size property available. If you open your window first and then create the label after, you will have access to this property without having to do the timeout hack.

      — commented December 21st 2011 by Justin Toth
    • setTimeout helped in my case as well, thx. I wonder why it cannot work as expected in our situations as well (read: would love if we wouldn't need such tweaks and sweat over the problem for any time).

      — commented January 4th 2012 by Tamas Rakoczi
  • Instead of using a timeout, I would recommend using the window's open event instead.

    myWindow.addEventListener('open', function(e)
        var uiElementHeight = uiElement.size.height;
        // Other code here...
    — answered December 30th 2011 by Nathan Warden
    1 Comment
    • I always get "auto" when I try to get the size like that

      — commented April 24th 2013 by Joris
  • I have this issue on the iPhone platform. For further development it would be nice if we could have getter setters method for objects inside titanium

    — answered March 31st 2010 by michel perrin
  • I'm not 100% on this, but as far as I know there is no way to do that.

    — answered March 31st 2010 by Dan Giulvezan
  • Thanks for your answer, too bad I cannot get this working

    — answered March 31st 2010 by michel perrin
    1 Comment
    • use the comment function

      — commented January 3rd 2011 by ben roe
  • Which platform(s)?

    — answered March 31st 2010 by Don Thorp
  • I have the same issue with SDK 1.7.5 in Android, and nothing seems to work!!!!

    — answered April 9th 2012 by Javier Hdez
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.