How can I change the separator line that appears at the end of each cell in UITableView? I want to have an image that is a thin separator type line image.
14 Answers
Set the separatorStyle
of the tableview to UITableViewCellSeparatorStyleNone
. Add your separator image as subview to each cell and set the frame properly.

- 32,945
- 35
- 107
- 137

- 35,354
- 13
- 96
- 143
-
1will you plz give me an example. – Mobile Developer iOS Android Jan 26 '11 at 12:46
-
[separatorImageView setFrame:CGRectMake(0, 0, cell.frame.size.width, separatorImageView.image.size.height)]; – Felix Jan 26 '11 at 12:54
-
[cell.imageView setFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)]; wasnt able to do so :( – cV2 Mar 16 '11 at 14:40
-
And what about the ones the normal UITableView draws when the cells don't fill the screen? – Christian Schnorr Apr 20 '12 at 20:31
-
4It's sad that this answer is still the best due to separator line bugs. – eonil Jun 24 '14 at 14:20
Try this
Objective C
[TableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[TableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Divider_line@2x.png"]]];
Swift
tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
tableView.separatorColor = UIColor(patternImage: UIImage(named: "YOUR_IMAGE_NAME")!)

- 1,060
- 11
- 25
-
1
-
1Thank you @ Sakshi - I set the separator color instead of an image and it looks great too. `table.separatorStyle = UITableViewCellSeparatorStyle.SingleLine table.separatorColor = UIColor(red: 245/255, green: 245/255, blue: 245/255, alpha: 1.0)` – fs_tigre Sep 27 '16 at 00:58
First you can write the code:
{ [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];}
after that
{ #define cellHeight 80 // You can change according to your req.<br>
#define cellWidth 320 // You can change according to your req.<br>
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seprater_line.png"]];
imgView.frame = CGRectMake(0, cellHeight, cellWidth, 1);
[customCell.contentView addSubview:imgView];
return customCell;
}
}

- 22,600
- 28
- 79
- 90

- 596
- 5
- 17
-
4The problem with solutions like this that just add a subview to the cell in `tableView:cellForRowAtIndexPath:` is that they will add a new one every single time the cell gets reused, never removing the old ones. It should only be added once, so you would do it in a `UITableViewCell` subclass. – Gavin May 13 '15 at 15:31
Set the color of the separator to be patterned with your image.
in viewDidLoad
:
self.tableView.separatorColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mySeparatorImage"]];

- 9,289
- 12
- 69
- 108

- 654
- 8
- 11
My project is based on iOS 7 This helps me
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
Then put a subview into cell as separator!

- 846
- 8
- 14
Try this:
UIImageView *separator = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"separator.png"]];
[cell.contentView addSubview: separator];
That's an example of how I got it to work pretty well.
Remember to set the separator style for the table view to none.

- 3,764
- 1
- 23
- 27

- 1,617
- 3
- 20
- 27
You can add a UIImageView that is, for example, 1 point high and as wide as the cell's frame, and then set its origin to the bottom left corner of the cell.

- 9,289
- 12
- 69
- 108

- 9,126
- 4
- 25
- 24
-
6Don't forget to turn off the default separator style for the table view: `[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];` – Jasarien Jan 26 '11 at 12:41
-
can u give me rough code so i can start, how can i set its origin to cell's bottom left corner ? – Mobile Developer iOS Android Jan 26 '11 at 12:43
Here's the way to do this via storyboard in XCode 10.2.1. Separator defaults to default
which is the line. Set it to none
to remove the line.

- 1,544
- 1
- 18
- 32
This is definitely help. Working. but set separator "none" from attribute inspector. Write following code in cellForRowAtIndexPath method
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,
cell.contentView.frame.size.height - 1.0,
cell.contentView.frame.size.width, 1)];
lineView.backgroundColor = [UIColor blackColor];
[cell.contentView addSubview:lineView];

- 12,549
- 4
- 53
- 52
-
I tried this even with `[cell.contentView bringSubviewToFront:lineView];` and it mostly doesn't show except the far right and left sides. – Timothy Swan Oct 09 '17 at 05:45
Swift 3/4
Custom separator line, put this code in a custom cell that's a subclass of UITableViewCell(or in CellForRow or WillDisplay TableViewDelegates for non custom cell):
let separatorLine = UIView.init(frame: CGRect(x: 8, y: 64, width: cell.frame.width - 16, height: 2))
separatorLine.backgroundColor = .blue
addSubview(separatorLine)
in viewDidLoad method:
tableView.separatorStyle = .none

- 160
- 4
- 9
Here is an alternate way to add a custom separator line to a UITableView
by making a CALayer
for the image and using that as the separator line.
// make a CALayer for the image for the separator line
CALayer *separator = [CALayer layer];
separator.contents = (id)[UIImage imageNamed:@"myImage.png"].CGImage;
separator.frame = CGRectMake(0, 54, self.view.frame.size.width, 2);
[cell.layer addSublayer:separator];

- 9,289
- 12
- 69
- 108

- 329
- 2
- 7
you can try below:
UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(0, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1)];
separator.backgroundColor = myColor;
[cell.contentView addSubview:separator];
or
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"separator.png"]];
imageView.frame = CGRectMake(0, 100, 320, 1);
[customCell.contentView addSubview:imageView];
return customCell;
}

- 568
- 7
- 19
Simplest way to add a separator line under each tableview cell can be done in the storyboard itself. First select the tableview, then in the attribute inspector select the separator line property to be single line. After this, select the separator inset to be custom and update the left inset to be 0 from the left.
You have 2 options to change the separator style of a uitableview if you want to change the default options which are no separators, solid line or etched line.
The easiest consist in including a separator line background image to each cell view. You may check then where is located your cell in the tableview to apply the right background image that will give you either a separator line on top of the cell or at the bottom of the cell.
Set the separator style to none in the viewDidLoad of your tableview:
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
Set your background image in the (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath function
UIImage* yourBgImg = [[UIImage imageNamed:@"bgImage.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
cell.backgroundView = [[UIImageView alloc] initWithImage:yourBgImg];
check the position of your cell in the section with the following:
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPathsection]]; NSInteger row = [indexPath row];
- Add the separator line as a cell. I find a post recently for this here: http://www.dimzzy.com/blog/2012/01/separator-cells-for-uitableview/#disqus_thread

- 11,477
- 5
- 43
- 61