Reputation: 5970
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.
Upvotes: 2
Views: 3679
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
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
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
Reputation: 5967
I think that is the separator of the tableview. You need to turn separators off. Heres a pic how to do so
Plz check and confirm.
I changed my demo file-
Colourd the cell background to green and turned separator off. As you can see 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]
Seems like there is no space as you wanted.
Upvotes: 2
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