0

I have a UItableView in which I am loading RSS. I would like to leave a space between each cell in the table view, as well as giving round corners to each cell, to give an effect like this one:

enter image description here

The problem is that I can't seem to find working code. Using:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10.; // you can have your own choice, of course
}

only adds space on top of the UITableView...

user2014474
  • 1,117
  • 5
  • 19
  • 36
  • Same question as this one: http://stackoverflow.com/questions/7189523/how-to-give-space-between-two-cells-in-tableview – LuisCien Jun 07 '13 at 16:20

4 Answers4

2

The easiest way to create this UI is to create a custom UITableViewCell that will have that extra space at bottom, if you can create a .png file that will be the gray background with the rounded corners or you can round the corners with view.layer.cornerRadius (don't forget to include QuartzCore for cornerRadius), add a label and an arrow and that's it.

danypata
  • 9,895
  • 1
  • 31
  • 44
2

No need to customize anything.

You have to initialize your tableView with a "groupedStyle". Or, if you you're using storyboard, set the style there. Then make the tableView background color to whatever you want.

myTableViewContoller = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];

the heightForHeaderInSection thing is for sections, not rows. you can do heightForRowAtIndexPath if you really need to for some reason.

Matjan
  • 3,591
  • 1
  • 33
  • 31
0

You can first make cells to be clear color background, then add a rounded corner view which should be smaller than the cell. This makes it looks like it gets a spacing around the cell.

Allan Jiang
  • 11,063
  • 27
  • 104
  • 165
0

This is an older one, but I ran into this problem recently. If your cells have a custom uiTableViewCell class add this to the bottom of the .m file of the class (just above @end)

- (void)setFrame:(CGRect)frame {
    frame.origin.y += 4;
    frame.size.height -= 2 * 5;  //adds the space and gives a 5 point buffer, can also indent the width using frame.size.width
    [super setFrame:frame];
}
user3344717
  • 161
  • 3
  • 5