Search code examples
imageviewtitaniumdefaultappceleratortitanium-mobile

Titanium : how to make a default "defaultImage" for all elements?


Is it possible to make a default "defaultImage" that will be used for all elements in my app (imageViews, coverflow, etc.) ? It will be great, instead of put "defaultImage" everywhere...

I've replaced the image called "photoDefault.png" in sdk_VERSION/iphone/modules/ui/, but I don't think it's the best trick...

Thank you


Solution

  • If you use the Alloy framework you can do it this way, just define a global View style in your app.tss:

    "ImageView" : {
       defaultImage : 'yourDefaultImage.png'
    }
    

    All image views will have this as there default background image now, unless you override it in code.

    If you don't want to use alloy, just do this instead:

    Titanium.UI.createImageView = Ti.UI.createImageView = function(attributes) {
        attributes.defaultImage = 'yourDefaultImage.png';
        var self = Titanium.UI.createImageView(attributes);    
        return self;
    }
    

    This just reassigns the Titanium namespace to a different function, that wraps the createImageView with your custom default image.