Skip to content
This repository was archived by the owner on Nov 18, 2024. It is now read-only.
This repository was archived by the owner on Nov 18, 2024. It is now read-only.

[Refactor] CollectionView Self-Sizing Cell 구현 #135

@ChoiysApple

Description

@ChoiysApple

Describe

  • 현재 대부분의 UICollectionView의 item 크기가 fixed 또는, figma 가이드를 보고 상수를 넣어 계산하는 방식으로 되어있음

Existing

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    let label = SPLabel(KRFont.B1_regular).then {
        $0.setText(string)
        $0.sizeToFit()
    }
    let size = label.frame.size
    let maxWidth = UIScreen.main.bounds.width - 32
    let additionalWidth: CGFloat = 24 + 14 + 8
    let width = min(maxWidth, additionalWidth + size.width)
    return CGSize(width: width, height: 40)
}
  • 이런 방식의 코드는 이슈 발생하기 쉬움
  • Cell UI 변경되면 엄청나게 열받는 상황 발생

Benefits

  • UI 구조 변경에 대응 가능

Reference

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions