Swift UITableViewCell 分割线从最左端开始

前言

系统默认的分割线距离最左端有一点距离,这是我们经常处理的一种情况是分割线到最左端,下面提供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 在最底部加上一根分割线
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值