Change color of label on tableViewRow when tapped
I have a tableView where the rows contain labels (with black text). The selectedBackgroundColor of the rows is red, so when the user taps a rows, I'd like to change the color of the labels to white to improve readability. I'm currently using the following code:
tableView.addEventListener('touchstart', function(e) {
e.row.children[0].color = '#fff';
});
tableView.addEventListener('touchend', function(e) {
e.row.children[0].color = '#000';
});
It works, but it's definitely buggy. Depending on how the user taps, it might not change the color to white at all, or it might change it to white and leave it as white when the row is deselected. Also, occasionally when the user taps a row, multiple rows are highlighted.
Is this a bug, or is there a better way to achieve this?
2 Answers
-
If anyone still having trouble with setting the selected color to a label in the table row.
The solution is:
var label = Ti.UI.createLabel({ HighlightedColor: 'white', color: 'black' });
By setting a property called "HighlightedColor" to a label, the color will be used when a click event has been triggered by a table row.
-
+1