Created
March 18, 2015 15:36
-
-
Save grantges/771a39ce3bfe9b1db185 to your computer and use it in GitHub Desktop.
A simple example of how to create a basic Widget using Appcelerator Titanium SDK and Alloy. This widget shows how you can create a cross platform view and external interfaces for programmatically setting properties of the widget.
This file contains 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
/** | |
* UnComment Out this Code to change the properties of your square | |
$.square.setBackgroundColor("blue"); | |
$.square.setHeight(200); | |
$.square.setWidth(200) | |
*/ | |
/** Opens the top level Window **/ | |
$.index.open(); |
This file contains 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
<Alloy> | |
<Window class="container"> | |
<!-- Declaration of the Widget. SRC refers to the name of the widget --> | |
<Widget src="square" id="square"/> | |
</Window> | |
</Alloy> |
This file contains 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
/** Incoming arguments to the Controller **/ | |
var _args = arguments[0] || {}; | |
/** Sets the Background Color **/ | |
exports.setBackgroundColor = function(color) { | |
$.square.backgroundColor = color; | |
}; | |
/** Sets the height of the View **/ | |
exports.setHeight = function(height) { | |
$.square.height = height; | |
}; | |
/** Sets the width of the View **/ | |
exports.setWidth = function(width) { | |
$.square.width = width; | |
} | |
/** Sets the height / width of the View to the same dimension **/ | |
exports.setSize = function(size) { | |
$.square.width = size; | |
$.square.height = size; | |
} |
This file contains 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
"#square":{ | |
backgroundColor: "red", | |
height: 100, | |
width: 100 | |
} |
This file contains 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
<Alloy> | |
<View id="square" /> | |
</Alloy> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment