How to give space between two cells in tableview?

前端 未结 26 1459
谎友^
谎友^ 2020-11-29 00:11

I want a space between two cell in table view,

I want cell like this,

\"enter<

相关标签:
26条回答
  • 2020-11-29 01:07

    I have used a simple and quick approach for this (using storyboard)

    • Add UITableView in your controller
    • Set the separator style to none (from attributes inspector)
    • Set the height of the row 5 pts more from top and bottom from the desired height
    • Now add an image in the cell, pin it from left and right but leave 5 pts space (for padding like feel) and set the background of the image same as the background you want for cell

    When the table view will be loaded, it will feel like there are spaces between cells.

    0 讨论(0)
  • 2020-11-29 01:08

    1) first create 2 sections in table view. 2) create an empty cell. 3) create the cell with data you want to display. 4) use the method

    • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section==0) {

      if (indexPath.row % 2 != 1) { return 15.0; } else { return 100; } } else

      if (indexPath.row % 2 != 1) {
          return 100.0;
      } else {
          return 15.0;
      }
      

    }

    It will add space between the cells. It worked for me.

    0 讨论(0)
提交回复
热议问题