본문 바로가기
🍎 iOS/문서읽기

[UIKit] UITableView의 구조

by @Eddy 2023. 7. 28.
728x90

Notion에 정리한 내용을 옮겨왔다.

 

UITableView 구조

Cell 자체는 ‘Delete Control - Content - Accessory View’의 구조로 되어 있다.

자세한 내용은 이전에 정리한 내용 참조

그렇다면 UITableView는 어떤 구조로 되어있을까?

  • ContentView - BackgroundView - SelectedBackgroundView - MultipleSelectionBackgroundView로 구성되어 있다.

contentView (= UIView)

contentView는 공식문서를 정리한 내용은 아래를 참조하면 될 것 같다.

이전에 정리한 내용을 참조


BackgroundView ( = UIView? )

backgroundView는 공식문서에서 다음과 같이 설명한다.

  • Cell의 background로 사용하기 위한 view
  • UITableViewCell은 다른 모든 뷰 뒤에 subView로서 backgroundView를 추가하고, backgroundView의 현재 프레임 위치를 사용한다.
  • 여러 줄 선택은 allowsMultipleSelection과 allowsMultiplesSelectionDuringEditing property를 통해 가능하다.
  • backgroundConfiguration과 병행 사용 불가.

selectedBackgroundView ( = UIView? )

  • selectedBackgroundView는 공식문서에서 다음과 같이 설명한다.
  • UITableViewCell은 cell이 선택된 상태일 때만 이 프로퍼티 값을 추가한다.
  • selectedBackgroundView가 nil이 아니면, backgroundView 위에 또는 다른 뷰들의 뒤에 subview로서 추가된다.
  • selSelected(_: animated: )를 호출하면 애니메이션 동작 가능
  • backgroundConfiguration과 병행 사용 불가.

multipleSelectionBackgroundView ( = UIView? )

  • multipleSelectionBackgroundView는 공식문서에서 다음과 같이 설명한다.
  • 여러 행을 선택할 때 selected cell에 사용하기 위한 backgroundView.
  • 만약 이 property가 nil이 아니라면, tableView가 여러 행 선택을 허용하면 selected cell에 대해 multipleSelectionBackgroundView가 backgroundView가 된다.
  • backgroundConfiguration과 병행 사용 불가.

backgroundConfiguration(iOS 14.0+)

  • UITableViewCell은 cell의 기본 형태를 제공하기 위해 자동적으로 기본 background configuration을 설정한다.
  • backgroundConfiguration을 사용하면 다양한 cell 상태에 대한 시스템 기본 스타일링을 얻을 수 있다.
  • 기본 시스템 스타일 중 하나를 사용해서 background configuration을 생성하고, 필요에 따라 cell style에 맞게 configuration을 사용자화하고, 이 속성에 configuration을 할당해라.
  • 아래는 해당 설명에 대한 코드이다.
  • var backgroundConfig = UIBackgroundConfiguration.listPlainCell() // Set a nil background color to use the view's tint color. backgroundConfig.backgroundColor = nil cell.backgroundConfiguration = backgroundConfig
  • background configuration은 backgroundView와 상호 독립적이라서, 둘 중 하나만 사용해야 한다.
  • background configuration을 non-nil로 설정했을 때, nil이 되는 속성들은 다음과 같다.
    • backgroundColor
    • backgroundView
    • selectedBackgroundView
    • multipleSelectedBackgroundView

참고자료

 

반응형

댓글