Last active
February 16, 2025 06:47
-
-
Save denandreychuk/3d7d4767e669dc9c41e67645289e4df9 to your computer and use it in GitHub Desktop.
Implementation of carousel in SwiftUI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct ContentView: View { | |
| var body: some View { | |
| ScrollView(.horizontal, showsIndicators: false) { | |
| LazyHStack(spacing: 10) { | |
| ForEach(Array(1...10), id: \.self) { id in | |
| RoundedRectangle(cornerRadius: 50) | |
| .fill(.yellow) | |
| .overlay { | |
| Text("\(id)") | |
| } | |
| .containerRelativeFrame(.horizontal) | |
| } | |
| } | |
| .scrollTargetLayout() | |
| } | |
| .contentMargins(.horizontal, 50, for: .scrollContent) | |
| .scrollTargetBehavior(.viewAligned) | |
| .frame(height: 400) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment