[英]How to create a horizontal list with only one element shown at a time?
我認為你想要的是一個水平的 ScrollView。 這是一個基本的實現。
有關更多信息,請參閱使用 Swift 進行黑客攻擊
struct ContentView: View {
let testData : [TestData] = [TestData(title: "Begginer"), TestData(title: "Medium"), TestData(title: "Hard")]
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 20) {
ForEach(testData, id: \.self) { data in
Text("\(data.title)")
.foregroundColor(.white)
.font(.largeTitle)
.frame(width: 300, height: 600)
.background(Color(.darkGray))
}
}
}
}
}
struct TestData: Hashable {
let title: String
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.