RGriffiths
RGriffiths

Reputation: 5970

UITableView - a line that appears between cells

I have a UITableView that stores photos taken - one photo per cell. Following an Xcode update some time ago the table now appears with a fine white line between the cells on the left as in pic 1. The image has always been indented from the left side of the table for some reason and it is only under this part that the white line now appears.

So I have two questions really - how can I get rid of the white line and/or the indent? The separator colour is usually the same as the background but I tried changing the separator colour in the TableView to red see what happens and I get what you see in pic 2. (The image thumbnails are irrelevant).

What I am hoping for is to keep the seperator (so there is a line between the photos) but to be abel to the colour of it so match the background colour.

enter image description here

Upvotes: 2

Views: 3679

Answers (5)

TigerCoder
TigerCoder

Reputation: 93

in the func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell function, add cell.backgroundColor = {color that you want}. This will make the white space the same as your background color.

Upvotes: 0

Chirag Kalsariya
Chirag Kalsariya

Reputation: 256

First you need set separators none

add custom separator like addSubview first get cell Height...

 UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(0, cellHeight-1, cell.frame.size.width, 1)];
            line.backgroundColor=[UIColor redColor];

 [cell addSubview:line];

Upvotes: 1

aramusss
aramusss

Reputation: 2401

Remove any separator from your tableView:

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

Then, from your UITableViewCells remove any space between the UIImageView and the view margins (setting constraints from example).

EDIT

You can set the separator color using the tableView property:

tableView.separatorColor = [UIColor greenColor];

Upvotes: 1

Saheb Roy
Saheb Roy

Reputation: 5967

I think that is the separator of the tableview. You need to turn separators off. Heres a pic how to do so

enter image description here

Plz check and confirm.

EDIT

I changed my demo file- Colourd the cell background to green and turned separator off. As you can see here enter image description here

And this is what i get after running the simulator [NOTE - I implemented the delegate and datasource methods, my numberOfRows has a return value of 5]

enter image description here

Seems like there is no space as you wanted.

Upvotes: 2

Nitin Gohel
Nitin Gohel

Reputation: 49730

By setting tableView.separatorStyle = UITableViewCellSeparatorStyleNone; That remove respirator from your tableview. but as per your existing code you used separator with same color. I suggest to use following code:

-(void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

Upvotes: 5

Related Questions