Changing background color of selected cell?

后端 未结 30 2991
太阳男子
太阳男子 2020-11-29 00:22

Does anyone know how to change the background color of a cell using UITableViewCell, for each selected cell? I created this UITableViewCell inside the code for TableView.

30条回答
  •  天命终不由人
    2020-11-29 00:56

    I've had luck with the following:

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        bool isSelected = // enter your own code here
        if (isSelected)
        {
            [cell setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:0.75 alpha:1]];
            [cell setAccessibilityTraits:UIAccessibilityTraitSelected];
        }
        else
        {
            [cell setBackgroundColor:[UIColor clearColor]];
            [cell setAccessibilityTraits:0];
        }
    }
    

提交回复
热议问题