iOS当UITableViewCell被选中或者高亮的时候,它的所有子view的颜色都会改变

来源:互联网 发布:32bit安装tensorflow 编辑:程序博客网 时间:2024/04/30 08:43
UITableViewCell changes the background color of all sub views when cell is selected or highlighted.
意思就是说当UITableViewCell被选中或者高亮的时候,它的所有子view的颜色都会改变。

如果你不喜欢让它变透明,你可以在你的自定义UITableViewCell里重写这两个方法:

假设那个view叫redline,它的颜色为红色。

// CustomTableViewCell.h

@interface CustomTableViewCell : UITableViewCell

@property (strong, nonatomic) UIView *redline;

@end

// CustomTableViewCell.h

@implementation CustomTableViewCell

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

-(void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    self.redline.backgroundColor = [UIColor redColor];
}

@end
0
0 0