您的位置:首页 > 移动开发 > Swift

Swift UITableViewCell 分割线从最左端开始

2017-08-16 22:56 239 查看

前言

系统默认的分割线距离最左端有一点距离,这是我们经常处理的一种情况是分割线到最左端,下面提供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 在最底部加上一根分割线
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: