Question

Here is a situation. I have a TableCell with a Icon and a Label. I want that when a PRESS the Cell, only my Label change Colors, without change the Background or anything, just the Text. How I do that?

The effect is like the one on Spotify app.

Spotify

Was it helpful?

Solution

You can use delegate methods of the UITableView for this.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell;
    // Initialize cell
    // If you want to use custom label, don't forget to set it a unique tag.
    cell.textLabel.text = @"Label";
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    // If you created a custom label, get it like the next line and then change the color of it;
    // UILabel * label = (UILabel *) [selectedCell viewWithTag: UNIQUE_TAG];
    selectedCell.textLabel.textColor = [UIColor redColor]; // Or which color you'd like.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top