Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize tableView separator in iPhone

By default there is a single line separator in uitableview.

But I want to put my customized line as a separator.

Is it possible? How?

like image 936
Sagar Kothari Avatar asked Sep 03 '09 18:09

Sagar Kothari


People also ask

What is separator inset?

The separatorInset property of UITableView is not new. It has been around since iOS 7 as a way to set the default inset for the separator between table view cells. It is a UIEdgeInsets but only the left and right values make any difference.

What is UITableView in Swift?

A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+


2 Answers

If you want to do more than change the color of the separator using the separatorColor property of the UITableView then you could set the separatorStyle property to UITableViewCellSeparatorStyleNone and then either:

  • create custom UITableViewCells that include your custom seperator within them
  • create alternate [UITableViewCell][6]s that include your custom separator

For example, if your table currently displays 5 rows you could update it to display 9 rows and the rows at index 1, 3, 5, 7 would be separator cells.

like image 151
Daniel Richardson Avatar answered Oct 23 '22 14:10

Daniel Richardson


A better solution is to use the cell's current width and height. Something like this:

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1)];  lineView.backgroundColor = [UIColor darkGrayColor]; [cell.contentView addSubview:lineView]; 
like image 38
Jerry Destremps Avatar answered Oct 23 '22 13:10

Jerry Destremps