Ios7 更改TableViewCell文本颜色

Ios7 更改TableViewCell文本颜色,ios7,uitableview,Ios7,Uitableview,这是一种情况。 我有一个带有图标和标签的TableCell。 我希望当按下单元格时,只有我的标签改变颜色,而不改变背景或任何东西,只有文本。 我怎么做到的 其效果与Spotify应用程序上的效果类似 您可以使用UITableView的委托方法进行此操作 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCel

这是一种情况。 我有一个带有图标和标签的TableCell。 我希望当按下单元格时,只有我的标签改变颜色,而不改变背景或任何东西,只有文本。 我怎么做到的

其效果与Spotify应用程序上的效果类似


您可以使用
UITableView
的委托方法进行此操作

- (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.
}

你为什么不改变标签的前景色呢?获取所选单元格,在单元格中找到标签,更改前景色。@Suresh前景色是什么意思?文本的常规颜色?我是如何做到的?这只有在我回来做标签时才起作用,而不是在我按下标签的那一刻。你能尝试一下
tableView:DidHighlightRowatineXpath:
方法吗
tableView:DidSelectRowatineXpath:
?可以,但有一个问题。所有标签都会改变颜色。我的TableCell有一个带有
出口的标签
,因此在
表格视图中:didHighlightRowatineXpath:
我将self.myLabel.textColor=[UIColor redColor];`当我使用
UITableViewCell*selectedCell=[tableView cellforrowatinexpath:indexPath]
selectedCell.textlab.textColor=[UIColor redColor]什么都不会发生。如果由于未显示单元格的
textlab
属性而未将字符串设置为该属性,则不会发生任何事情。如果您有插座,请更改其文字颜色。