Reputation: 1507
I'm using a tableview in my app that has lines not reaching until the end of the row:
In my design I need some of the lines to reach all the way like in this picture:
Also another problem I have is that I see the last line in the tableview:
My question is how do I make some of the lines all the way across like in the 2nd picture and another question is how do I remove the last line of the UITableView ?
Upvotes: 0
Views: 1164
Reputation: 173
For Xcode 15 and Swift 5 on Storyboard
Inside Storyboard of Attribute Inspector make Sperator Inset Custom and you can give leading and trailing inset.
Upvotes: 0
Reputation: 355
to remove that last line or all other lines you have set tableView.tableFooter = UIView()
in cellForRowAt
Upvotes: 0
Reputation: 1701
You can change insets of seperator for last cell in tableview so it will disappear from screen.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableviewCell", for: indexPath) as! TableviewCell
if indexPath.row == LastCount {
cell.separatorInset = UIEdgeInsets(top: 0, left: UIScreen.main.bounds.width*2, bottom: 1, right: -(UIScreen.main.bounds.width*3))
}
else
{
cell.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
return cell
}
Upvotes: 0
Reputation: 12594
You can use below code for the tableviewcells in which you want it to be touched to edge of tableview.
cell.separatorInset = UIEdgeInsets.zero
cell.layoutMargins = UIEdgeInsets.zero
Note: As tableview uses reusable cells, so if you are setting separatorInset
and layoutMargins
, then make sure you are setting it for all cells. Otherwise reused cell will have different separator inset then expected. So, for other cells, keep left=16 in UIEdgeInsets
.
for case of hiding the separator case, you have to again play with separatorInset
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, UIScreen.main.bounds.width)
Upvotes: 2
Reputation: 106
You are using custom cell so you can use label/view for line, set the label/view leading and trailing constraints or update label/view height, color according to your requirements and set the table view separator None.
Set the condition for last row of table in Table cellForRowAt function and hide the label/view.
Upvotes: 0
Reputation: 181
add a view with light gray background with height of 1 and append to the top of cell. customize in each cell as you needed.
Upvotes: 0