Link
Notice
HIT해
[SwiftUI] 스크롤뷰 두개씩 배치하기 본문
728x90
ScrollView(.horizontal) {
LazyHStack {
// 배열이 비어 있지 않은 경우에만 내부 로직 실행
if !items.isEmpty {
ForEach(0..<items.count, id: \.self) { index in
// 짝수 인덱스만 처리하여 두 개씩 그룹화
if index % 2 == 0 {
VStack {
// 현재 아이템
if items.indices.contains(index) {
NavigationLink(destination: UpdateBookMarkView(item: items[index])) {
HStack{
VStack(alignment: .leading){
Spacer()
HStack{
Text("\(items[index].cdTitle)").foregroundColor(.white).padding(.leading, 10).padding(.bottom,7).lineLimit(1).fontWeight(.semibold)
Spacer()
}
}
VStack(alignment : .trailing){
Text("사진").hidden()
Spacer()
}
}.frame(width : UIScreen.main.bounds.width * 0.43, height : 100).background( LinearGradient(colors: [gradientColors[index] ,gradientColors[index].opacity(0.9)], startPoint: .bottom, endPoint: .top)).cornerRadius(10)
}
}
// 다음 아이템 (있을 경우)
if items.indices.contains(index + 1) {
NavigationLink(destination: UpdateBookMarkView(item: items[index + 1])) {
HStack{
VStack(alignment: .leading){
Spacer()
HStack{
Text("\(items[index+1].cdTitle)").foregroundColor(.white).padding(.leading, 7).padding(.bottom,10).lineLimit(1)
Spacer()
}
}
VStack(alignment : .trailing){
Text("사진").hidden()
Spacer()
}
}.frame(width : UIScreen.main.bounds.width * 0.43, height : 100).background( LinearGradient(colors: [gradientColors[index+1] ,gradientColors[index+1].opacity(0.7)], startPoint: .bottom, endPoint: .top)).cornerRadius(10)
}
}else{
Spacer()
}
}.frame(maxWidth : UIScreen.main.bounds.width / 2 )
}
}
'Swift > UIKit 개발 노트' 카테고리의 다른 글
[iOS/Swift] Asset 추가하기 / 여러개의 카탈로그 만들기 (0) | 2024.08.16 |
---|---|
앱스토어 배포하기 - 처음부터 끝까지 (0) | 2024.04.16 |
[SwiftUI] 기울어지게 배치하기 (0) | 2024.03.30 |
[SwiftUI] 배경 그라데이션 적용하기 (0) | 2024.03.20 |
[SwiftUI] 카메라 앱 기능 구현하기 (AVFoundation) (0) | 2024.03.19 |