Titanium Community Questions & Answer Archive

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

Views and labels

Hi All

Im trying to simply layout a window and I have fallen at the first hurdle.

I have a business Name with a telephone number underneath which is coming from a database.

The business Name could go over two lines and I want to maintain the top and bottom padding and the distance from the Name and the telephone number.

The code below formats nicely but goes pear shape when the text goes over two lines. I thought of putting the telephone number in a view and that would move down as the text gets longer. still did not work. Out of ideas now.


var header = Ti.UI.createView({
    backgroundColor:'#fff',
    top:0,
    height:'auto',    
    width:320,
});

var businessName = Ti.UI.createLabel({
        text: result.fieldByName('Name'),
        color:'#333',
        font:{fontSize:18,fontWeight:'Normal', fontFamily:'Arial'},
        left:16,
        height:'auto',
        top:0,
        bottom: 16
});

var Telephone = Ti.UI.createLabel({
    text: 'Telephone: '+result.fieldByName('Telephone'),
    color:'#333',
    font:{fontSize:12, fontWeight:'Normal', fontFamily:'Arial'},
    left:16,
    top: 40,
    height: 14,
    bottom: 16,
});


header.add(businessName);
header.add(Telephone);
win.add(header);

Many thanks

— asked March 30th 2010 by Mark Pierce
  • iphone
  • layout
  • titanium.ui.label
  • titanium.ui.view
0 Comments

1 Answer

  • Accepted Answer

    Set the buisinessName label to a blob:

    buisinessName.toBlob();
    

    Now you have access to the width and height parameters. nex thing to do is set your Telephone labels height to:

    top: (buisinessName.y + buisinessName.height) + spacing,
    
    — answered March 30th 2010 by Glenn Tillemans
    permalink
    0 Comments
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.