How to increase the UITableView separator height?

后端 未结 17 2215
花落未央
花落未央 2020-12-08 00:19

I want more space(10px) between each cell. How can I do this?

And I have added this code

tableView.separatorStyle = UITableViewCellSepar         


        
17条回答
  •  一个人的身影
    2020-12-08 00:41

    For a table cell with height of 50 and a space of 5 pix between the rows. Width is 320.

    Define the background of the cells to be clear:

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
        cell.backgroundColor = [UIColor clearColor];
    }
    

    Set the height of the cells, this is the size of the row PLUS the delimiter:

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return 55;
    }
    

    And define in cellForRowAtIndexPath a box, with the size of the row (MINUS delimiter) to draw in the background color:

    UILabel *headerBackgroundLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,320,50)];
    backgroundBox.backgroundColor = [UIColor grayColor];
    [cell addSubview:backgroundBox];
    

提交回复
热议问题