Click on image added to button

You must Login before you can answer or comment on any questions.

Hi,

I have the following code

(note coffee script)

button = Titanium.UI.createButton
 
image = Titanium.UI.createImageView
  image: 'image.png'
 
button.add(image)
 
image.addEventListener 'click', (e) ->
  Ti.API.log("I AM CLICKED")
Is there a way to make the image appear above the button even though its added to the button itself?

1 Answer

I have found the best way to make fancy buttons is to cheat... I create a button with an image in photoshop, use an imageview with the photoshopped button in it, then i create an transparent button ontop of the imageview. This way you can make a button exactly how you want it! If you want the button to change when its clicked, make 2 button images in photoshop and update the imageview when the transparent button is clicked.

var image = Titanium.UI.createImageView({
    image:'../images/buttonimage.png',
    height:45,
    width:130
})
win.add(image);
 
var button = Titanium.UI.createButton({
    width:130,
    height:45,
    opacity:0.0
});
win.add(button);
 
button.addEventListener('click', function(e){
Ti.API.info('Button Clicked');
});
Adam.

Your Answer

Think you can help? Login to answer this question!