UITableView separator line disappears when selecting cells in iOS7

后端 未结 24 2143
耶瑟儿~
耶瑟儿~ 2020-12-05 04:01

In my tableView I set a separator line between cells. I am allowing selection of multiple cells. Here\'s my code for setting selected cell background color:

         


        
24条回答
  •  长情又很酷
    2020-12-05 04:21

    use this:

    - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        UIView *selectionColor = [[UIView alloc] init];
        selectionColor.backgroundColor = [UIColor clearColor];
        cell.selectedBackgroundView = selectionColor;
        //71
        UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 71, 320, 2)];/// change size as you need, where - 71 - y coordinate, 320 - weight, 2 - height
      //  separatorLineView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"divider_goriz.png"]];// you can also put image here
        separatorLineView.backgroundColor = [UIColor redColor];
        [cell.selectedBackgroundView addSubview:separatorLineView];
        return YES;
    }
    

提交回复
热议问题