White space before separator line into my TableView

后端 未结 8 1994
青春惊慌失措
青春惊慌失措 2020-11-30 19:49

I have a question about UITableView... I have a UITableViewController and I created a custom cell. When I visualize the tableView I see a little white space before the separ

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 20:40

    Here is an extension to UITableViewCell Class for swift 3 & later

    extension UITableViewCell
    {
        func removeSeparatorLeftPadding() -> Void
        {
            if self.responds(to: #selector(setter: separatorInset)) // Safety check
            {
                self.separatorInset = UIEdgeInsets.zero
            }
            if self.responds(to: #selector(setter: layoutMargins)) // Safety check
            {
                self.layoutMargins = UIEdgeInsets.zero
            }
        }
    }
    

    Usage:

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    {
        let cell : UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "menuCellID")!
        // .. Your other code
        cell.removeSeparatorLeftPadding()
        return cell
    }
    

    Hope this helps some one!

    Naresh.

提交回复
热议问题