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 labels are unclickable?

I have a button, with a label. If you click on the non-label part, the button will work just fine. If you click on the label (text), then it wont register a click, or show the selected state.

Would anyone have any ideas on how to resolve this? :)

Thanks a mill!

// CREATE LABEL
var buttonLabel = Ti.UI.createLabel({ 
        text: 'Find Out More', color: '#4e3216',
        shadowColor:'#FFFFE6', shadowOffset:{x:0,y:1}, 
        textAlign:'center', top:8, 
        width: 'auto', height:'auto',
        font:{fontWeight:'bold',fontSize:17} 
});

// CREATE BUTTON
var moreBtn = Titanium.UI.createButton({
    height:40, width:270, bottom:25,
    style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN,
    borderColor:'#b89f73', borderRadius:10, borderWidth:1, 
    backgroundImage:'../images/ui/button-bg.png', 
    backgroundSelectedImage:'../images/ui/button-bg-selected.png'
});

// ASSIGN LABEL TO BUTTON
moreBtn.add(buttonLabel);

// ASSIGN CLICK EVENT TO BUTTON
moreBtn.addEventListener('click', function(){
    Ti.Platform.openURL('http://www.google.com');
});
— asked November 10th 2010 by Glen McPherson
  • buttons
  • click
  • events
  • iphone
  • labels
0 Comments

1 Answer

  • Glen

    Try setting the label's touchEnabled property to false

    — answered November 10th 2010 by Paul Dowsett
    permalink
    2 Comments
    • See my answer in this post for an example of working code with a label covering a button.

      — commented November 11th 2010 by Paul Dowsett
    • This solved my problem!! Thanks!

      — commented January 26th 2011 by Scott Millar
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.