Remove separator line for only one cell

后端 未结 13 2241
萌比男神i
萌比男神i 2020-12-30 19:38

I\'m trying to remove the separator for one UITableViewCell. I did the following:

- (UITableViewCell *)tableView:(UITableView *)tableView cellFo         


        
13条回答
  •  臣服心动
    2020-12-30 19:56

    On iOS 8 you need to use:

    cell.layoutMargins = UIEdgeInsetsZero
    

    If you want to be compatible with iOS 7 as well you should do following:

    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    

    ADD: If previous didn't work - use this. (from answer below)

     cell.separatorInset = UIEdgeInsetsMake(0, CGFLOAT_MAX, 0, 0);
    

    If none of above worked, you can do:

    self.tableView.separatorColor = [UIColor clearColor];

    but this will leave 1 pixel empty space, not really removing a line, more making it transparent.

提交回复
热议问题