【发布时间】:2019-10-27 02:27:45
【问题描述】:
在我研究 swiftUI 中的 scrollView 时寻求一些帮助。 我有一个显示数组值的滚动视图,基于当用户点击滚动视图的不同项目时,我想在下面的 textField 上显示它。
如何将数组值传递给文本字段??
import SwiftUI
struct ContentView: View {
let post = ["TEST1 ","Test 2" , "Test 3","TEST4 ","Test 5" , "Test 6"]
var temp = ""
var body: some View {
VStack {
ScrollView(.horizontal, content: {
HStack(spacing: 100) {
ForEach(post, id: \.self){ item in
ZStack {
Rectangle().foregroundColor(.blue).frame(width: 190, height: 170, alignment: .center)
Text(item)
}.onTapGesture {
// pass the value off Scroll View to the text
debugPrint("\(item)")
}
}
}
.padding(.leading, 10)
})
.frame(height: 190)
Spacer()
Text("dispaly here array value selected")
Spacer()
}
}
}
谢谢你帮助我...
【问题讨论】:
标签: arrays swift scrollview swiftui