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.
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.
Set the separatorStyle of the tableview to UITableViewCellSeparatorStyleNone. Add your separator image as subview to each cell and set the frame properly.
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:
{ #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;
}
}
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):
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.