在viewDidLoad()添加一下代码
if tableView.responds(to:#selector(setter: UITableViewCell.separatorInset)) {
tableView.separatorInset = UIEdgeInsets.zero
}
if tableView.responds(to:#selector(setter: UIView.layoutMargins)) {
tableView.layoutMargins = UIEdgeInsets.zero
}
tableview实现多以下代理
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if cell.responds(to:#selector(setter: UIView.layoutMargins)) {
cell.layoutMargins = UIEdgeInsets.zero
}
if cell.responds(to: #selector(setter: UITableViewCell.separatorInset)) {
cell.separatorInset = UIEdgeInsets.zero
}
}