UITableView Separator Line

How to change the separator line that appears at the end of each cell in a UITableView? I want to have an image that is an image of a thin separator line.

+74
iphone uitableview
Jan 26 '11 at 12:36
source share
14 answers

Set the separatorStyle the view table to UITableViewCellSeparatorStyleNone . Add a spacer image as a spy to each cell and adjust the frame correctly.

+88
Jan 26 2018-11-12T00:
source share

try it

Goal 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")!) 
+58
May 21 '13 at 7:30
source share

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; } } 
+29
Sep 11 '12 at 17:50
source share

Set the color of the separator that will have the picture with your image.

in viewDidLoad :

 self.tableView.separatorColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mySeparatorImage"]]; 
+7
Jul 16 '13 at 18:37
source share

My project is based on iOS 7. It helps me

[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

Then put the subview in the cell as a separator!

+5
Jul 07 '14 at 12:09 on
source share

You can add a UIImageView, which, for example, is 1 point higher and the frame width of the cell, and then set its beginning to the lower left corner of the cell.

+4
Jan 26 2018-11-12T00:
source share

Try the following:

 UIImageView *separator = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"separator.png"]]; [cell.contentView addSubview: separator]; 

This is an example of how I got it to work very well.

Remember to set the separator style to represent the table not equal.

+4
Apr 18 2018-12-18T00:
source share

It definitely helps. At work. but set the separator to "none" from the attribute inspector. Write the following code in the 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]; 
+2
Oct. 14 '16 at 10:38
source share

Swift 3/4

Custom delimiter, put this code in a custom cell, which is a subclass of UITableViewCell (either in CellForRow or WillDisplay TableViewDelegates for non-user cells):

 let separatorLine = UIView.init(frame: CGRect(x: 8, y: 64, width: cell.frame.width - 16, height: 2)) separatorLine.backgroundColor = .blue addSubview(separatorLine) 

in the viewDidLoad method:

 tableView.separatorStyle = .none 
+1
Aug 09 '17 at 17:53 on
source share

You have 2 options for changing the style of the uitableview separator if you want to change the default settings that are not separators, a solid line or an etching line.

  • The simplest of them is that in the background image there are separator lines for each type of cell. You can check where your cell is in the tableview to apply the correct background image, which will give you either a dividing line on the top of the cell or the bottom of the cell.

    Set the separator style to none in the viewDidLoad of your TableView:

    [self.tableView setSeparatorStyle: UITableViewCellSeparatorStyleNone];

    Set the background image to 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 your cell position in the section with the following:

    Section NSIntegerRows = [tableView numberOfRowsInSection: [indexPathsection]]; NSInteger row = [indexPath row];

  • Add a dividing line as a cell. I recently found a post for this. Here: http://www.dimzzy.com/blog/2012/01/separator-cells-for-uitableview/#disqus_thread
0
Feb 15 2018-12-15T00:
source share

The following is an alternative way to add a separate separator row to a UITableView by creating a CALayer for the image and using this as a separator row.

// create a CALayer for the image for the separator string

 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]; 
0
Feb 27 '14 at 23:15
source share

you can try:

 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; } 
0
Jun 27 '16 at 10:34
source share

The easiest way to add a dividing line below each tableview cell can be done in the storyboard itself. First select the table view, then in the attribute inspector select the separator line property as one line. After that, select the separator insert to adjust and update the left insert on the left.

Example

0
Sep 25 '17 at 10:41
source share

Here is a way to do this through the storyboard in Xcode 10.2.1. The default separator for default string. Set to none to delete the row.

tableview_separator

0
Jun 20 '19 at 0:11
source share



All Articles