Fabiano Soriani
Fabiano Soriani

Reputation: 8562

Titanium.UI.Label property height

In my code I am doing this:

var taskLabel = Ti.UI.createLabel({color:'#777', top:3, textAlign:'center', height:'auto', text:task.title});
Ti.API.info('Next info is: taskLabel.height');
Ti.API.info(taskLabel.height);

But, the output from this is:

[INFO] [123,883] Next info is: taskLabel.height

And nothing more, it looks like it breaks silently, but I guess it shouldn't, based on the API.

I am trying to sum some heights of the elements, but I would prefer it behaved like html postion:relative. Anyway, I'd like to read the height in float, how can I achieve that?

Upvotes: 0

Views: 1060

Answers (4)

rbawaskar
rbawaskar

Reputation: 1045

This should work.

 var lbl_obj = Ti.UI.createLabel( { height: 'auto', text:'Test Label', top:10 } );
 var height = lbl_obj.toImage().height;
 Ti.API.info(height);

Upvotes: 0

Applehat
Applehat

Reputation: 668

You cant read the height property off like that, if you didn't manually define it.

It has to be added to a view, and then displayed (assuming it doesn't auto display) before Titanium will return anything about the height.

var window = Ti.UI.createWindow();
var taskLabel = Ti.UI.createLabel({color:'#777', top:3, textAlign:'center', height:'auto', text:task.title});
window.add(taskLabel);
window.open();
Ti.API.info('Next info is: taskLabel.height');
Ti.API.info(taskLabel.height);

That should work to show the height.

Upvotes: 0

Matt
Matt

Reputation: 501

You need to set a fixed width when you use an auto height. For example:

var taskLabel = Ti.UI.createLabel({color:'#777', top:3, textAlign:'center', height:'auto', width: 200, text:task.title});

Upvotes: 1

Aaron Saunders
Aaron Saunders

Reputation: 33345

you are not going to get the height until it is actually rendered and added to view or window.

Upvotes: 0

Related Questions