👔StackForEach
⬆️ 需要:📦 ScrollHStackForEach, 📦 ScrollVStackForEach
struct ContentView: View {
var body: some View {
HStack {
Group {
// 📦 ScrollHStackForEach
ScrollHStackForEach(0..<60) { numberBall($0) }
// 📦 ScrollVStackForEach
ScrollVStackForEach(0..<30) { numberBall($0) }
.frame(height: 400)
}
.border(Color.yellow) // scroll view border (yellow)
.padding()
.background(Color.gray4)
.border(Color.pink) // padding border (pink)
.padding()
}
}
}
extension ContentView {
/// number in a circle
func numberBall(_ i: Int) -> some View {
ZStack {
Circle()
.fill(Color.purple)
.frame(width: 60, height: 60)
Text("\(i)")
}
.font(.largeTitle)
.shadow(radius: 4)
}
}
Last updated
Was this helpful?