본문 바로가기
IOS - Swift

[iOS/Swift] TableVIew 높이 유동적으로 조절하기

by 게게겍 2023. 1. 24.
extension ViewController: UITableViewDelegate {
    
    // 테이블뷰 셀의 높이를 유동적으로 조절하고 싶다면 구현할 수 있는 메서드
    // (musicTableView.rowHeight = 120 대신에 사용가능)
//    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
//        return 120
//    }
    
    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }

}

 

UITableView.automaticDimension 메서드를 이용하여 높이를 유동적으로 조절할 수 있습니다