How to set the full width of separator in UITableView

前端 未结 16 794
再見小時候
再見小時候 2020-11-30 19:50

I have a UITableView where the separators don\'t have the full width. It ends like 10 pixels before the left side. I was playing around with this code in the

相关标签:
16条回答
  • 2020-11-30 20:51

    swift 5, Xcode 11 Update

    place this inside viewDidLoad()

    yourTableView.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    

    for edge to edge separator just set the value of left and right to 0.

    by the way change the "yourTableView" to your tableView Outlet name.

    0 讨论(0)
  • 2020-11-30 20:52

    For Swift 3 :

    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        if cell.responds(to: #selector(setter: UITableViewCell.separatorInset)) {
            cell.separatorInset = UIEdgeInsets.zero
        }
        if cell.responds(to: #selector(setter: UITableViewCell.layoutMargins)) {
            cell.layoutMargins = UIEdgeInsets.zero
        }
        if cell.responds(to: #selector(setter: UITableViewCell.preservesSuperviewLayoutMargins)) {
            cell.preservesSuperviewLayoutMargins = false
        }
    }
    
    0 讨论(0)
  • 2020-11-30 20:54

    For Swift in iOS 9+

    If using a custom UITableViewCell:

    override var layoutMargins: UIEdgeInsets {
        get { return UIEdgeInsetsZero }
        set(newVal) {}
    }
    

    then for your UITableView in viewDidLoad:

    self.tableView?.separatorInset = UIEdgeInsetsZero;
    self.tableView?.layoutMargins = UIEdgeInsetsZero;
    
    0 讨论(0)
  • 2020-11-30 20:56
    1. Select your UITableViewCell
    2. Go to Atributes Inspector
    3. Go to Separator and change it to "custom Insets"
    4. Set left and / or right fields. (By default left: 15, right: 0)

    Look how it works (using left: 100):

    Result:

    0 讨论(0)
提交回复
热议问题