티스토리 뷰
반응형
CollectionViewCompositionalLayout은 간격을 조정하는 여러 가지 방법이 있습니다. item 간의 간격, section 간의 간격, header 및 footer의 크기와 간격 등을 조정할 수 있습니다.
item 간의 간격을 조정하려면 NSCollectionLayoutSpacing 객체를 사용할 수 있습니다. 이 객체는 space, lineSpacing, and interItemSpacing 같은 여러가지 속성을 가지고 있으며, 이를 조정함으로써 item 간의 간격을 조정할 수 있습니다.
예를 들어, 아래 코드는 NSCollectionLayoutSpacing을 사용하여 각 item 간의 간격을 10으로 설정하는 방법을 보여줍니다.
Swift 코드
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.25), heightDimension: .fractionalHeight(1.0))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let itemSpacing = CGFloat(10)
let groupSpacing = CGFloat(10)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(50))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = groupSpacing
section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
section.interGroupSpacing = groupSpacing
section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
let spacing = NSCollectionLayoutSpacing.fixed(itemSpacing)
section.contentInsets.bottom = itemSpacing // 종료 item의 마진 주기
section.interItemSpacing = spacing
let layout = UICollectionViewCompositionalLayout(section: section)
따라서, item의 contentInset을 조정하지 않고도 item 간의 간격을 조정할 수 있습니다.
반응형
'Mobile > iOS' 카테고리의 다른 글
| 외부의 웹페이지를 wkwebview 로 불러올 때, 앱에 설치된 커스텀 폰트로 표시되게 할 수 있나요? (0) | 2023.04.23 |
|---|---|
| 맥북을 껏다 켜니 계속 이 시동 디스크를 검사하려면 인터넷 연결이 필요합니다. 라고 메시지박스가 뜹니다. 해결책은 무엇일까요? (1) | 2023.04.15 |
| MVVM 사용 시 어떤 view 에 대한 delegate 가 필요할때 상황에 따라 ViewModel 이 delegate 를 채택하는 것도 괜찮은 방법인가요? (0) | 2023.04.08 |
| Hero iOS 라이브러리 (0) | 2023.04.04 |
| Lottie 강력하고 가벼운 애니메이션 라이브러리 (0) | 2023.04.03 |
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- react
- 성경책
- youtube
- mysql
- flutter
- 성경통독
- 오디오북
- 통독
- AWS
- 말씀
- 플러터
- 아이폰
- iPhone
- 1일1독
- 유튜브
- IOS
- 성경읽기
- genesis
- Android
- ChatGPT
- 성경
- bible
- VR
- MariaDB
- 반응형웹
- 아이폰개발
- 창세기
- 성경듣기
- 안드로이드
- SWIFT
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
글 보관함