how to get label height ?

You must Login before you can answer or comment on any questions.

Hi, I need to get the height of a label whose width and height are set to as Ti.UI.SIZE. Apparently i will be adding another label dynamically whose top has to be set to the first label's height.

I tried with `secondLabel.top=firstLabel.height+20' but they overlaps since Ti.API.info(firstLabel.height) returns as SIZE.

Iam using 2.02 GA . pls help me out with a sample reg how to add labels dynamically with top based on previous height when labels are set to Ti.UI.SIZE for both width and height .

1 Answer

Accepted Answer

Hi Karthi,

You can do it many ways.

1.Post Layout event.

2.Using toImage() like this.

var i = view.toImage();
i.width;
i.height;

— answered 11 months ago by Nitin Chavda
answer permalink
4 Comments
  • Hi Nitin,

    Thanks for letting me know of the possible ways. If i use label.toImage() for dynamic calculation of heights will it lead to memory related probems? could you please help me provide a snippet for labels using postLayout as you have mentioned for the requirement?

    — commented 11 months ago by karthi keyan

  • toImage() works like charm . thanks a lot Nitin. will it lead to any memory prob? if so kindly help in how to use the postLayout event for labels

    — commented 11 months ago by karthi keyan

  • If you have few UI elements then it does not lead any memory prob.

    for Post Layout

    label.addEventListener('postlayout', function(e) {
            var label_height = e.source.rect.height;
            alert(label_height);
        });

    — commented 11 months ago by Nitin Chavda

  • Show 1 more comment

Your Answer

Think you can help? Login to answer this question!