Configuration

Judy·2022년 7월 30일
0

iOS

목록 보기
20/28

Configuration

View Configuration

셀의 콘텐츠와 스타일을 구성하는 새로운 API (iOS 13)


background configurations

배경 모양을 빠르게 지정할 수 있는 여러 속성이 있음
ex) backgroundColor, Insets and corner radius, Custom View ..

content configurations

표준 레이아웃
ex) Text, Image, Secondary Text ..


예시

let cell: UITableViewCell = ...
var contetn = cell.defaultContentConfiguration()
// 콘텐츠가 설정되지 않은 새 구성이 항상 반환
// cell 및 TableView 스타일을 기반으로 하는 기본 스타일

content.image = UIImage(...)
content.text = "Hello"

cell.contentConfiguration = content
  • UIImage나 UILabel에 직접 접근하지 않음
  • configuration을 지원하는 셀 또는 뷰에 모두 적용할 수 있음

configuration이란

content, styling, metrics and behavior과 같은 특정 상태의 view 모양을 설명
= 속성의 묶음

장점

  • 가볍고 생산 비용이 적음

Configuration State

Configuration과 함께 작동하여 다양한 상태에 대해 다른 모양을 쉽게 얻을 수 있도록 함

  • 셀과 뷰를 구성하는 데 사용하는 다양한 입력을 나타낸다

ex) Traits

  • 셀의 상태 -> 선택됨, 끌어다 놓는 중, 일시적인 비활성화 등
  • Cell Configuration State / View Configuration State

Congiguration 변경

var automaticallyUpdatesContentConfigurations: Bool { get set}
var automaticallyUpdatesBankgroundConfigurations: Bool { get set}

셀의 구성 상태가 변경될 때마다 구성에 자동으로 업데이트된 자체 버전을 반환하도록 요청한 다음 해당 새 구성을 셀에 다시 적용하도록 요청 -> 기본 configuration을 가져오기 용이

직접 업데이트 하고 싶을 때

func updatesConfigurations(using state: UIConfigurationState)
  • 상태를 기반으로 구성을 변경할 수 있음
  • 항상 셀이 처음 표시되기 전에 호출
  • 구성 상태가 변경될 때마다 다시 호출

  • 셀을 재구성해야 하는 경우 setNeedsUpdateConfiguration을 호출하여 업데이트를 요청




Modern cell configuration

profile
iOS Developer

0개의 댓글