How to change color of UITableViewCell when selecting?

前端 未结 14 2509
予麋鹿
予麋鹿 2020-12-04 10:59

I have a menu like so:

\"Menu\"

The normal (unselected) state for each cell is an image, the selected s

14条回答
  •  执笔经年
    2020-12-04 11:30

    I end up with following code.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
      //  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[cellIdArray objectAtIndex:indexPath.row] forIndexPath:indexPath];
    
        // Configure the cell...
        cell.backgroundView =
        [[UIImageView alloc] init] ;
        cell.selectedBackgroundView =[[UIImageView alloc] init];
    
        UIImage *rowBackground;
        UIImage *selectionBackground;
    
    
        rowBackground = [UIImage imageNamed:@"cellBackgroundDarkGrey.png"];
        selectionBackground = [UIImage imageNamed:@"selectedMenu.png"];
    
        ((UIImageView *)cell.backgroundView).image = rowBackground;
        ((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;
    
    
    
        return cell;
    }
    

提交回复
热议问题