How do I set UITableViewCellSelectionStyle property to some custom color?

前端 未结 9 1761
栀梦
栀梦 2020-12-13 04:04

I am developing an iPhone application, in my table view I wanted custom color for Cell Selection Style, I read the UITableViewCell Class Reference but there are onl

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 04:41

    - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
        return YES;
    }
    
    - (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
        // Add your Colour.
        SocialTableViewCell *cell = (SocialTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        [self setCellColor:Ripple_Colour ForCell:cell];  //highlight colour
    }
    
    - (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath {
        // Reset Colour.
        SocialTableViewCell *cell = (SocialTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        [self setCellColor:Ripple_Colour ForCell:cell]; //normal color
    
    }
    
    - (void)setCellColor:(UIColor *)color ForCell:(UITableViewCell *)cell {
        cell.contentView.backgroundColor = color;
        cell.backgroundColor = color;
    }
    

提交回复
热议问题