[iOS] UITableView Cell 왼쪽 여백지우기

ungchun·2022년 4월 16일
0
post-thumbnail

Custom Cell을 이용해서 TableView 구성 중인데 모든 곳에 autolayout superView 0 으로 잡아도 왼쪽 여백이 계속 생기는 것이다. 그래서 구글링을 통해 알아보니 생각보다 많은 사람들이 이런 상황을 겪었던 것 같다. ( 참고링크 1, 참고링크 2 )

해결법

// view controller
...
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "identifier")
tableView.separatorInset = .zero
tableView.directionalLayoutMargins = .zero
tableView.layoutMargins = .zero
...

// data source
...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = tableView.dequeueReusableCell(withIdentifier: "identifier")!
    cell.directionalLayoutMargins = .zero
    cell.layoutMargins = .zero
    cell.contentView.directionalLayoutMargins = .zero
    cell.contentView.layoutMargins = .zero
    return cell
}

0개의 댓글