Created
March 30, 2011 03:24
-
-
Save jonalter/893810 to your computer and use it in GitHub Desktop.
Creating Reusable Factories and Using Ti.App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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