SwiftUI

[SwiftUI] ScrollView Paging 하기

쵱니 2025. 5. 10. 01:37

App Store에서 미리보기 저 스크롤은 페이지 스크린샷 만큼씩만 페이지가 넘어간다.

TabView로 구성하면 될까 싶었지만

TabView는 한 페이지에 1개씩 밖에 안된다. 저렇게 반쯤 걸쳐져 있는 것은 구현이 안된다.

ScrollView(.horizontal) {
    HStack {
        ForEach(0..<4) {
            Image("kakaoBankScreenShot\($0)")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: imageWidth)
        }
    }
    .padding(.horizontal, horizontalPadding)
    .scrollTargetLayout()
}
.scrollIndicators(.never)
.scrollTargetBehavior(.viewAligned)

방법은 .scrollTargetBehavior(.viewAligned) .scrollTargetLayout() 이다

해당 방법을 통해서 원하는 크기 만큼씩 Scroll을 조절할 수 있다.