Skip to content

Instantly share code, notes, and snippets.

@jasonkneen
Last active August 29, 2015 14:01
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasonkneen/d8b738ecc8379e3c01ba to your computer and use it in GitHub Desktop.
Save jasonkneen/d8b738ecc8379e3c01ba to your computer and use it in GitHub Desktop.
DynamicLabel tag in Alloy - allows you to update a "value" and it applies it to a template. Place ui.js in your app/lib folder
$.recordCount.value = 99
<Alloy>
<View class="container">
<DynamicLabel module="ui" id="recordCount" value="0" template="? Records"/>
</View>
</Alloy>
exports.createDynamicLabel = function(args) {
var label = Ti.UI.createLabel(args);
function updateText() {
label.text = label.template.replace("?", label.value);
}
label.getValue = function() {
return label.value;
};
label.setValue = function(value) {
label.value = value;
updateText();
};
updateText();
return label;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment