0

I have at problem with my cells in a UITableView. I have used the Attribute Inspector to adjust the size. Like this:

enter image description here

But the adjustment only applied on the cells with content. How do I make the separator to be the same size for the whole tableview using Swift or the Attribute Inspector?

enter image description here

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
Lasse Bickmann
  • 195
  • 3
  • 14

1 Answers1

0

For your question, you can try this

tableView.tableFooterView = UIView()

Another way you can do like this.

Then,

In cellForRowAtIndexPath

tableView.separatorStyle = .none
let horizontalGap = 15.0 as CGFloat
// As you want to have equal gaping in left & right side, you have to position the view's origin.x to the constant and have to have the width minus the double of that constant.
let seperatorView = UIView(frame: CGRect(x: horizontalGap, y: cell.frame.size.height - 1, width: cell.frame.size.width - horizontalGap * 2.0, height: 1))
seperatorView.backgroundColor = UIColor.red
cell.addSubview(seperatorView)

In Storyboard

Change Separator as None in Attributes Inspector. Drag UIView and place it inside your cell . Give constraints like, Leading 15, Trailing 15, Bottom 0 and height 1. Change background color to red

McDonal_11
  • 3,935
  • 6
  • 24
  • 55