經(jīng)常有需求隱藏一個section的最后一條分割線, 然而自定義cell有些過于繁瑣
我們都知道設(shè)置某一條分割線的邊距位0
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0)
隱藏某一條cell的分割線
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, __kScreenWidth/** cell的寬 */)
但是在iOS9下效果頗有不理想
設(shè)置邊距位0
Paste_Image.png
隱藏分割線
Paste_Image.png
解決辦法 追加以下方法
//iOS9 分割線 隱藏或者設(shè)置邊距0
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if cell.responds(to: #selector(setter: UIView.preservesSuperviewLayoutMargins)) {
cell.preservesSuperviewLayoutMargins = false
}
if cell.responds(to: #selector(setter: UIView.layoutMargins)) {
cell.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0)
}
}