Skip to content

Instantly share code, notes, and snippets.

@ejjonny
Created March 17, 2022 04:08
Show Gist options
  • Save ejjonny/1c7b023b61bb743b1501b9b887d47c88 to your computer and use it in GitHub Desktop.
Save ejjonny/1c7b023b61bb743b1501b9b887d47c88 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@State var animate = false
let iconSize: CGFloat = 95
let iconCount = 20
let iconPadding: CGFloat = 5
var marqueeWidth: CGFloat {
(iconSize * CGFloat(iconCount)) + (iconPadding * (CGFloat(iconCount) - 1))
}
var body: some View {
GeometryReader { geo in
HStack(spacing: iconPadding) {
ForEach(0..<iconCount, id: \.self) { i in
RoundedRectangle(cornerRadius: 21)
.frame(width: iconSize, height: iconSize)
.foregroundColor(.indigo)
.overlay {
Text("\(i)")
}
}
}
.frame(width: marqueeWidth)
.offset(
x: animate ? -(marqueeWidth - geo.size.width) : 0
)
}
.animation(.linear(duration: 10).repeatForever(autoreverses: true), value: animate)
.onAppear {
animate.toggle()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment