Swift 4
It is not possible to make the default delimiter higher. Instead, you need to add a subview that will look like a separator for each cell (and, optionally, make the cell higher). You can do this, for example, in cellForRowAtIndexPath or in a subclass of UITableViewCell .
If you allow to select a cell, you also need to add a subview for the selected state, otherwise the separator will disappear when you select a cell. This is why selectedBackgroundView also configured.
Add this to your subclass of UITableViewController :
override func viewDidLoad() { super.viewDidLoad() tableView.separatorStyle = .none } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) cell.backgroundView = UIView(backgroundColor: .white) cell.backgroundView?.addSeparator() cell.selectedBackgroundView = UIView(backgroundColor: .blue) cell.selectedBackgroundView?.addSeparator()
Add these extensions to the same file below:
private extension UIView { convenience init(backgroundColor: UIColor) { self.init() self.backgroundColor = backgroundColor } func addSeparator() { let separatorHeight: CGFloat = 2 let frame = CGRect(x: 0, y: bounds.height - separatorHeight, width: bounds.width, height: separatorHeight) let separator = UIView(frame: frame) separator.backgroundColor = .gray separator.autoresizingMask = [.flexibleTopMargin, .flexibleWidth] addSubview(separator) } }
Marián Černý Aug 03 '18 at 16:16 2018-08-03 16:16
source share