How do I set UITableViewCellSelectionStyle property to some custom color?

前端 未结 9 1767
栀梦
栀梦 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:44

    If you have subclassed a UITableViewCell, then you can customise the various elements of the cell by overriding the following:

    - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
        if(highlighted) {
            self.backgroundColor = [UIColor redColor];
        } else {
            self.backgroundColor = [UIColor clearColor];
        }
    
        [super setHighlighted:highlighted animated:animated];
    }
    

    EDIT for iOS7: as Sasho stated, you also need

    cell.selectionStyle = UITableViewCellSelectionStyleNone
    

提交回复
热议问题