jasonkneen
5/13/2014 - 4:48 PM

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

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

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;
};
<Alloy>
	<View class="container">
		<DynamicLabel module="ui" id="recordCount" value="0" template="? Records"/>
	</View>
</Alloy>
$.recordCount.value = 99