Titanium Community Questions & Answer Archive

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

Button width:

This is not working, although according to the documentation it should:
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Button-object

var btExample = Ti.UI.createButton({
    title:'Animate',
    top: 100,
    height: '60',
    ***width: 'auto'***
});

The button doesn't show up.
No error messages.

This does work:

var btExample = Ti.UI.createButton({
    title:'Animate',
    top: 100,
    height: '60',
    ***width: '100'***
});

Titanium Developer 1.2.1

— asked September 7th 2010 by Joacim Boive
  • button
  • iphone
  • mobile
0 Comments

3 Answers

  • Same problem here with a View + Label:

    var view_btn = Ti.UI.createView({width:'auto',height:40,top:0,backgroundImage:"button.png",name:"btn"});
    
    var lbl_btn = Ti.UI.createLabel({
    text:"test,
    height:'auto',
    width:'auto',
    color:'#FFF',
    font:{fontSize:15},
    textAlign:'center',
    name:"lbl"
    });
    
    view_btn.add(lbl_btn);
    

    android looks fine, on iphone the view is only as wide as the label and centered

    — answered September 10th 2010 by Michael G.
    permalink
    0 Comments
  • @Joacim:

    height:60
    

    not

    height:'60'
    
    — answered September 10th 2010 by Dan Tamas
    permalink
    0 Comments
  • @Dan Tamas: Does not change the fact that width: 'auto' on buttons still isn't working.
    And OP's question is a year old…

    Example:

    var win = Titanium.UI.createWindow({  
      backgroundColor:'#fff',
      fullscreen: false
    });
    
    var b = Titanium.UI.createButton({top: 10, left: 10, width: 150, height: 30, title:' Download ',style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED});
    var b2 = Titanium.UI.createButton({top: 100, left: 10, width: 'auto', height: 30, title:' Download ',style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED});
    
    win.add(b);
    win.add(b2);
    
    win.open();
    

    —-> Button 2 is just not showing up :(

    Anyone has an idea how to fix this?
    Thanks, Thomas

    — answered February 13th 2012 by Thomas Martin
    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.