UICollectionViewCompositionalLayout 🍎

YaR LabΒ·2023λ…„ 8μ›” 7일
0

iOS 🍎

λͺ©λ‘ 보기
12/26
post-thumbnail

1️⃣ μ •μ˜

μœ μ—°ν•˜κ³  λ‹€μ–‘ν•œ λ°©μ‹μœΌλ‘œ μ½˜ν…μΈ λ₯Ό λ°°μΉ˜ν•˜λŠ” λ ˆμ΄μ•„μ›ƒ 객체, 이λ₯Ό μ‚¬μš©ν•˜λ©΄ μ½˜ν…μΈ λ₯Ό 자유둭게 μ‘°ν•©ν•˜μ—¬ μ›ν•˜λŠ” μ‹œκ°μ  배열을 λ§Œλ“€ 수 있음

@MainActor
class UICollectionViewCompositionalLayout : UICollectionViewLayout

2️⃣ μ„€λͺ…

  • compositional layout은 μ»¬λ ‰μ…˜ 뷰의 νŠΉλ³„ν•œ ν˜•νƒœλ‘œ, μ½˜ν…μΈ λ₯Ό λ‹€μ–‘ν•˜κ³  μœ μ—°ν•˜κ²Œ λ°°μΉ˜ν•˜λŠ” κΈ°λŠ₯을 제곡
  • μž‘μ€ ꡬ성 μš”μ†Œλ“€μ„ μ‘°ν•©ν•˜μ—¬ μ½˜ν…μΈ λ₯Ό μ›ν•˜λŠ” μ‹œκ°μ  ν˜•νƒœλ‘œ λ§Œλ“€ 수 있음
  • λ ˆμ΄μ•„μ›ƒμ„ λ§Œλ“€κΈ° μœ„ν•΄ κ°„νŽΈν•˜κ²Œ μ„Ήμ…˜μ„ μ‘°ν•©ν•˜κ³ , 각 μ„Ήμ…˜ μ•ˆμ—μ„œλ„ ν•­λͺ©λ“€μ„ κ·Έλ£Ήν™”ν•˜μ—¬ λ°°μΉ˜ν•  수 있음
  • κ·Έλ£Ή μ•ˆμ—μ„œ ν•­λͺ©λ“€μ€ κ°€λ‘œ, μ„Έλ‘œ λ˜λŠ” μ‚¬μš©μžκ°€ μ •μ˜ν•œ ν˜•νƒœλ‘œ λ°°μ—΄ν•  수 있음
  • λ‹€μ–‘ν•œ λ””μžμΈκ³Ό μ‹œκ°μ  효과λ₯Ό μ‰½κ²Œ κ΅¬ν˜„ν•  수 있음

πŸ“Œ μ˜ˆμ‹œ μ½”λ“œ

func createBasicListLayout() -> UICollectionViewLayout { 
    let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),                                  
                                         heightDimension: .fractionalHeight(1.0))    
    let item = NSCollectionLayoutItem(layoutSize: itemSize)  
  
    let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),                                          
                                          heightDimension: .absolute(44))    
    let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize,                                                   
                                                     subitems: [item])  
  
    let section = NSCollectionLayoutSection(group: group)    


    let layout = UICollectionViewCompositionalLayout(section: section)    
    return layout
}

μΆœμ²˜πŸ“š

🍎Apple Docs: UICollectionViewCompositionalLayout

0개의 λŒ“κΈ€

κ΄€λ ¨ μ±„μš© 정보