I'm trying to create an image button. (a custom image that looks like it would be in the same family as the SystemButton.INFO_LIGHT one)
The createButton code has a backgroundImage property -so this should be doable right? Heck I even see buttons with images in the kitchen sink app.
But when I cut and paste the code (changing the image paths of course) ... nothing.
As far as I can tell none of the following do... anything.
image:'../iphone/help_20.png', backgroundImage:'../iphone/help_20.png', backgroundSelectedImage:'../iphone/help_20_on.png', backgroundDisabledImage: '../iphone/help_20_off.png',I've checked my paths about billion times. But for the life of me I can't seem to:
Create a button from an image!!
If any one can help me figure out what I'm missing I'd be most grateful.
7 Answers
Accepted Answer
Glad that I was able to help.
Dont forget to set the title, even blank, and set the width and height. It doesnt get from the image file. Can you put the whole code?
The code below is failing to create ANYTHING.
Am I missing something obvious here? Do I somehow need to register the images I want to use with the app?
var alertButton2 = Titanium.UI.createButton({ backgroundImage:'../iphone/help_20.png', width:22, height:22, title:'', right:15, top:49 });
Jeffrey Messick shot me the answer. If he chimes in here I'll mark his answer.
Turns out the "iphone" directory is a special one. It can hold the default and app icon... but other images wont resolve there.
Created a different directory and all seems to be well.
...ugh... thanks Jeffery!
Weird... I can get the images (and thus the buttons to show) if I use absolute paths. Relative paths aren't resolving.
The code is in screen1.js which is in the "main_windows folder under the "Resources" folder.
screen1.js being called from app.js which is in the "Resources" folder..
And the images are in the "iphone" folder under the "Resources" folder."
But I get nothing If I use the path:
backgroundImage:'../iphone/alert2_54.png',So I thought "maybe" it needs to be relative to app.js but I still get nothing using:
backgroundImage:'iphone/alert2_54.png',... ? ... this should not be hard ... ?
I'm seriously confused. In a fit of desperation I changed this:
backgroundImage:'/Users/xxxx/Desktop/v2/yyyy/Resources/iphone/alert2_54.png',to this:
backgroundImage:Titanium.App.appURLToPath('alert2_54.png'),It worked like a champ in the simulator, but of course errored out in a big red screen once it hit the hardware.
Please check this article about platform-specific images. Note that this does not work for iPhone Simulator at the moment. Please check this bug for details.
Your Answer
Think you can help? Login to answer this question!