Search
⛓️

Grid

부제
카테고리
SwiftUI
세부 카테고리
컴포넌트
Combine 카테고리
최종편집일
2022/09/20 08:17
작성중
관련된 포스팅
생성 일시
2022/07/16 15:56
태그
안녕하세요 iOS 개발자 루크입니다
오늘은 Grid 사용법을 간단 명료하게 정리해보고자 합니다.

Grid 사용법

LazyVGrid(columns: [GridItem(.adaptive(minimum: 120), spacing: 20)], spacing: 20) { ForEach(0..<30) { item in RoundedRectangle(cornerRadius: 10) .fill(Color.blue) .frame(height: 160) } }
Swift
복사

LazyVGrid

수직으로 늘어나는 형태의 Grid 를 그리고 필요한 항목만을 메모리에 로드함.

columns : [GridItem]

→ 열에대한 내용 정의
GridItem 을 담고있는 어레이를 전달해 주어야 함.
GridItem 에 대한 설명은 아래에서 참고
추가 하면 할수록 화면에 보여지는 개수가 변함!

GridItem

A description of a single grid item, such as a row or a column.
각 그리드의 항목의 레이아웃, 간격, 정렬등을 커스터마이징

spacing

VGrid 의 경우 행간격 결정
HGrid 의 경우 열간격 결정

alignment

부모뷰 내에서의 그리드 전체의 얼라인을 결정

pinnedViews

Views to pin to the bounds of a parent scroll view.

content

The content of the grid.
각 그리드 내부 컨텐츠 뷰를 결정
ForEach 와 함께 사용

GridItem

.Size

각 항목의 사이즈를 결정하는 파라미터
adaptive(minmum: CGFloat, maximum: CGFloat)
Multiple items in the space of a single flexible item.
fixed(CGFloat)
A single item with the specified fixed size.
flexible(minimum: CGFloat, maximum: CGFloat)
A single flexible item.

spacing

다음 항목과의 간격
VGrid 의 경우 열간격
HGrid 의 경우 행간격

alignment

각각의 뷰의 align 결정