1

is it possible to make a distance between cells like that in standard UITableView? There is no options to make separator bigger. Also this distance from right and left.

enter image description here

1
  • you need a custom separator view. try a search .
    – Pawan Rai
    Feb 11, 2014 at 18:43

5 Answers 5

6

you can do this by set your cell background to whatever background you want (let's say gray in this case) and in the cell, add a white uiview with left, right, and bottom margin like this:

enter image description here

Then go to your table view, set the separator as none

enter image description here

and one last step, set the background of your table view to the same gray background as your cell.

enter image description here

Then you don't have to do anything particularly in your code besides simply initial your table cell based on the custom nib file (i assume you want to do this anyway).

If you prefer to construct your cell in codes, you can use the same logic.

1

in method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

     ...

  cell.backgroundColor = [UIColor whiteColor];

  // This will create a line of 3 pixels that will be separating the cells
  UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,3)];
  separator.backgroundColor = [UIColor darkGrayColor];
  [cell.contentView addSubview: separator];

  // and if you want the border do left and right add:
  UIView *separatorRx = [[UIView alloc] initWithFrame:CGRectMake(318,0,2,cell.frame.size.height)];
  separatorRx.backgroundColor = [UIColor darkGrayColor];
  [cell.contentView addSubview: separatorRx];

  UIView *separatorSx = [[UIView alloc] initWithFrame:CGRectMake(0,0,2,cell.frame.size.height)];
  separatorSx.backgroundColor = [UIColor darkGrayColor];
  [cell.contentView addSubview: separatorSx];

  return cell;

}

enter image description here

0

One way would be to set the backgroundView of the UITableViewCell to an UIImageView containing this white box on that gray background

0

You have to make a subclass of UITableViewCell. In your own subclass you may make everything you dream about! So, you need to add UIView with whiteColor background and margins as subview on your custom UITableViewCell.

0

There is not padding option in UITableView. You can either add a UIView in your UITableViewCell which will contains all the cell subviews, and change it's frame to create a padding right in the cell.

I suggest you to use UICollectionView instead, you can easily set the space between cells using a layout. If the cell is smaller than the actual collection View, then it's automatically centered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.