Titanium Community Questions & Answer Archive

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

***Bug*** Label 'Auto' Height Broken in 1.4.2

This is the code being used( with the text being dynamically updated and changed )

var labelHere = Ti.UI.createLabel({
    color:'#808080',
    font:{fontSize:18,fontWeight:'bold', fontFamily:'Helvetica'},
    textAlign:'left',
    top:0,
    left:0,
    height:'auto',
    width:319,
    zIndex:3,
    text:stringVariable
});

WORKS under
iOS 4.1
Mobile SDK 1.4.1.1

But it breaks when under
iOS 4.1
Mobile SDK 1.4.2

Whenever adding content to the label, the height does not increase and just shows ellipsis. When populating the label's text initially, it does have an 'auto' height, but it does NOT work when adding more to the label's text property after that initial setup.

any help would be greatly appreciated!!!

rocksteady,
danno~

— asked November 22nd 2010 by danno watts
  • 1.4.1.1
  • 1.4.2
  • 4.1
  • auto
  • height
  • ios
  • iphone
  • label
  • mobile
2 Comments
  • Danno

    Can we see a bit more of your code? Where are you adding it, and what to?

    — commented November 22nd 2010 by Paul Dowsett
  • it's over 2000 lines of code in the .js file, so can't post it all, but simplified it's the label above added to a view, which that view is added to a scrollView.
    all of it works under 1.4.1.1 , but under 1.4.2 it doesn't.

    — commented November 22nd 2010 by danno watts

6 Answers

  • Accepted Answer

    dont add the height property in label….

    — answered November 25th 2010 by Andrew Remigius
    permalink
    0 Comments
  • more code showing it in context:

    
    var scrollView = Titanium.UI.createScrollView({
        contentWidth:320,
        layout:'vertical',
        contentHeight:'auto',
        top:0,
        showVerticalScrollIndicator:true,
        showHorizontalScrollIndicator:false
    });
    
    var theView = Ti.UI.createView({
        width:319,
        height:'auto',
        top:5,
        left:8
    });
    
    var labelHere = Ti.UI.createLabel({
        color:'#808080',
        font:{fontSize:18,fontWeight:'bold', fontFamily:'Helvetica'},
        textAlign:'left',
        top:0,
        left:0,
        height:'auto',
        width:319,
        zIndex:3,
        text:stringVariable
    });
    
    theView.add(labelHere);
    
    scrollView.add(theView);
    

    WORKS under iOS 4.1 Mobile SDK 1.4.1.1
    But it breaks when under iOS 4.1 Mobile SDK 1.4.2

    is there a new, stable version that is above 1.4.2 that i can try out? or any other suggestions?

    — answered November 22nd 2010 by danno watts
    permalink
    0 Comments
  • Danno

    Try the latest Continuous Build, that you can download from the link in the install instructions page, and let us know if the problem persists.

    — answered November 22nd 2010 by Paul Dowsett
    permalink
    2 Comments
    • i've downloaded it and i'll try it in the next few minutes to see what happens. quick side question, how are people using the latest build of 1.5, i've seen on other questions here that people are saying they are using 1.5 ( not 1.4 )

      — commented November 23rd 2010 by danno watts
    • Danno

      1.5 is not yet considered stable, so if you are going to use it, and something does not work, you have to be prepared to test the issue in 1.4.X to ensure it's not 1.5-specific before considering it a problem (or raising it in this Q&A)

      — commented November 24th 2010 by Paul Dowsett
  • just tried latest build and it did NOT fix the issue :(

    rocksteady,
    danno~

    — answered November 23rd 2010 by danno watts
    permalink
    0 Comments
  • Try forcing a refresh on the parent scroll view and container view after you've updated the label text (by changing some random property):

    labelHere.text = 'New string';
    theView.width = 318;
    theView.width = 319;
    scrollView.contentWidth = 319;
    scrollView.contentWidth = 320;
    

    Or even forcibly resetting the height of the label:

    labelHere.text = 'New string';
    labelHere.height = 20;
    labelHere.height = 'auto';
    
    — answered November 24th 2010 by James K
    permalink
    0 Comments
  • Danno

    The label in this code changes height to accommodate the extra text after you click on the button, using android 2.2, Ti SDK 1.4.X. Would you test it in your environment?

    Ti.UI.setBackgroundColor('#000');
    
    var tabGroup = Titanium.UI.createTabGroup();
    
    var window = Titanium.UI.createWindow({  
        title:'window 1',
        backgroundColor:'red'
    });
    
    var button = Titanium.UI.createButton({
        title:"change label",
        width:100
    });
    window.add(button);
    
    var stringVariable = "short label text";
    
    var labelHere = Ti.UI.createLabel({
        backgroundColor:'white',
        color:'#808080',
        font:{fontSize:18,fontWeight:'bold', fontFamily:'Helvetica'},
        textAlign:'left',
        top:10,
        left:0,
        width:319,
        zIndex:3,
        text:stringVariable
    });
    
    button.addEventListener('click',function(e)
    {
        labelHere.text = "this is some very long text to prove whether or not the label height will dynamically change accordingly";
    });
    
    window.add(labelHere);
    
    window.open();
    
    — answered November 24th 2010 by Paul Dowsett
    permalink
    1 Comment
    • i'll take a look at that. glad it works in android, would you mind seeing if it works on iOS with the configuration you currently have?

      — commented November 25th 2010 by danno watts
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.