Post

UIKIt - UITableView 동적 height 설정하기

UIKIt - UITableView 동적 height 설정하기

예시

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import UIKit

final class SettingViewController: UIViewController {
    
    private lazy var tableView: UITableView = {
        let tableView = UITableView(frame: .zero, style: .insetGrouped)
        
        // 셀 높이를 내부 컨텐츠에 맞춰 자동 조정
        tableView.rowHeight = UITableView.automaticDimension
        
        // 미리 추정 높이 설정
        tableView.estimatedRowHeight = 100
        
        return tableView
    }()
}

Cell 내부 UI 요소에서 마지막 요소에는 반드시 bottom 제약을 줘야함.

Reference

This post is licensed under CC BY 4.0 by the author.