Skip to content

Instantly share code, notes, and snippets.

@jonalter
Created March 30, 2011 03:24
Show Gist options
  • Select an option

  • Save jonalter/893810 to your computer and use it in GitHub Desktop.

Select an option

Save jonalter/893810 to your computer and use it in GitHub Desktop.
Creating Reusable Factories and Using Ti.App
// Please note that this is a dirty solution.
// It does work, but Appcelerator does not support it (adding things to the Ti namespace).
// There is a very good chance that it will not be possible in future releases.
Ti.include('ui.js');
var win = Ti.App.ui.createCustomWindow();
var button = Ti.App.ui.createCustomButton();
win.add(button);
win.open();
(function() {
Ti.App.ui = {};
Ti.App.ui = {
createCustomWindow: function() {
var win = Ti.UI.createWindow({
backgroundColor: 'green'
});
return win;
},
// This will work fine in Android and iOS
createCustomButton: function() {
var button = Ti.UI.createButton({
title: 'OK',
height: 60,
width: 150
});
return button;
}
};
// This method will not work in iOS
// Ti.App.ui.createCustomButton will be undefined
// Ti.App.ui.createCustomButton = function() {
// var button = Ti.UI.createButton({
// title: 'Not for iOS',
// height: 60,
// width: 150
// });
// return button;
// };
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment