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 Transparency

Anyone know how to make a button WITH and image obey the alpha channel stuff for transparency?

I thought this would work, but it doesn't. If I load sample.png into Photoshop, you can see the transparency layer is in fact there. I am placing my button over an ImageView, but the button transparency layer is showing up white rather than with the imageView behind.

var btnTest = Titanium.UI.createButton({
  image:'sample.png',
  left:10,
  top:10,
  backgroundColor:'transparent'
});
— asked October 30th 2010 by Steven Day
  • button
  • iphone
  • transparency
0 Comments

2 Answers

  • Accepted Answer

    Instead of setting the image try loading the image into backgroundImage and define the height and width. I am using code like this and it honors that transparency in the PNG.

      var btnTest = Ti.UI.createButton({
        backgroundImage: 'sample.png',
        height: 24,
        width: 20,
        top:  10,
        left:10
      });
    
    — answered October 30th 2010 by John McKnight
    permalink
    0 Comments
  • 
    var btnTest = Titanium.UI.createButton({
      image:'sample.png',
      left:10,
      top:10,
      opacity:0.1 // 0.0 - 1.0
    });
    
    — answered October 30th 2010 by Michael Updegraff
    permalink
    2 Comments
    • This is right if you just want to apply an opacity overlay.
      Thanks.

      — commented June 5th 2013 by Skylar Bolton
    • according to appcelerator titanium documentation(http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.Button) this is the legit answer.

      — commented March 23rd 2015 by sinan talebi
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.