默认情况下,cell被选中时,会变成灰色。但是如果你的cell里只有一部分显示内容的话,而你只想让中间部分变成灰色,而不是整个cell时
实现代码如下:
1.cell在初始化时
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectedBackgroundView = [[UIView alloc] init];
self.selectedBackgroundView.backgroundColor = tableView_color;
}
- (void)layoutSubviews {
[super layoutSubviews];
self.selectedBackgroundView.frame = CGRectMake(0, 0, self.width, 85);
}2.在cellForRowAtIndexPath里千万不要把cell.selectionStyle 设成 UITableViewCellSelectionStyleNone