前言
系统默认的分割线距离最左端有一点距离,这是我们经常处理的一种情况是分割线到最左端,下面提供3种解决办法供大家参考
方法1
此方法的实现略微复杂
//在初始化tableview时,加上这两句
if tableView.responds(to:#selector(setter: UITableViewCell.separatorInset)) {
tableView.separatorInset = .zero
}
if tableView.responds(to: #selector(setter: UITableViewCell.layoutMargins)) {
tableView.layoutMargins = .zero
}
//......
//在代理中实现
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if cell.responds(to: #selector(setter: UITableViewCell.separatorInset)) {
cell.separatorInset = .zero
}
if cell.responds(to: #selector(setter: UITableViewCell.layoutMargins)) {
cell.layoutMargins = .zero
}
}
方法2
//在初始化tableView 时加上这一句即可
tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0)
//或者
tableView.separatorInset = UIEdgeInsets.zero
方法3
//初始化tableView时隐藏掉系统的分割线
tableView.separatorStyle = .none
//自定义tabelViewCell 在最底部加上一根分割线