UITableViewCell 커스터마이징

김윤홍·2024년 7월 23일
0
post-thumbnail

UITableViewCell에 대한 고민들

코드를 작성하다보니 TableViewCell들의 간격을 넓혀주고 싶었고 cell을 클릭하면 다른 확장뷰가 나오게 구현을 해보고싶었다..

TableViewCell 간격설정하기

extension UsageHistoryController: UITableViewDelegate, UITableViewDataSource {

//section에 들어갈 cell은 하나만 설정해서 섹션으로 구분하고 cell아래에 footer추가하기
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 1 }
  
  //cell아래에 투명한 footerView추가하기 
  
  func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let footerView = UIView()
    footerView.backgroundColor = .clear
    return footerView
  }
  
  //투명한 footerView의 넓이를 설정해 cell간격 조절하기
  func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 10 }
}
  
  }

위의 방법으로 cell을 section으로 나누고 cell아래에 투명한 footer view를 추가한후 footerView의 넓이로 cell 간격을 정해준다

ExpandableCell 만들기

다음은 cell클릭시 cell이 확장되게 만들어보자!

먼저 ExpandableCell이라는 UITableViewCell을 채택해 클래스를 만들고 셀클릭시 cell View가 나오도록한다.

0개의 댓글

관련 채용 정보