[Apple] UICollectionViewFlowLayout

J.Noma·2022년 1월 9일
0

Reference


✅ Remind

  • FlowLayout은 한 쪽으로만 scroll이 가능하다
  • scrollDirection에 따라, 세로방향이 row/line일수도(vertial), 가로방향이 row/line일수도 있다(horizontal)

Overview

flow layout이란
flow layout은 CollecionView layout의 한 종류입니다. CollecionView에 있는 item들은 scroll direction 설정에 따라 row 혹은 column 방향으로 전개됩니다. 각 row는 주어진 CollectionView 공간 안에 최대한 cell을 채우게 됩니다. cell들의 크기는 모두 같을 수도 있고 다르게 줄 수도 있습니다

flow layout과 delegate (UICollectionViewDelegateFlowLayout)
flow layout은 각 section과 grid 내의 item/header/footer 크기를 결정하기 위해 CollecionView의 delegate와 함께 동작합니다. 이 delegate는 UICollectionViewDelegateFlowLayout 프로토콜을 채택해야 합니다. 이 delegate를 사용하는 것은 layout 정보를 동적으로 변경할 수 있게 해줍니다. 예로, grid 내 item들이 서로 다른 크기를 갖도록 delegate에 명시할 수 있습니다. 만약 delegate를 제공하지 않는다면, flow layout은 자신에게 설정된 default 값을 사용합니다

scroll direction
flow layout은 한 방향의 너비는 고정하고 다른 방향은 scroll이 가능하도록 content를 놓습니다. 예로, 수직 scroll grid 내에서는 내부 content의 width가 CollecionView의 width까지로 제한됩니다. 반면, content의 height는 얼마든지 동적으로 늘어날 수 있습니다. scroll direction은 default 수직방향이며, scrollDirection 프로퍼티를 통해 수평방향으로 바꿀 수도 있습니다

section별 custom header/footer
flow layout 내 section은 자신만의 custom header/footer를 가질 수 있습니다. 이를 위해, header/footer의 size를 non-zero로 설정해주면 됩니다. 적절한 delegate 메서드를 구현하고 headerReferenceSizefooterReferenceSize 프로퍼티에 적절한 값을 할당합니다. 이 프로퍼티들의 값을 0으로 설정하면, CollectionView에 추가되지 않게 됩니다

profile
노션으로 이사갑니다 https://tungsten-run-778.notion.site/Study-Archive-98e51c3793684d428070695d5722d1fe

0개의 댓글