我是SwiftUI的初学者,更新我的应用程序并在SWIFTUI上重新制作它。这是我要做的截图..。屏幕截图
我已经成功地完成了同样的工作,但问题是,我有一堆白色的盒子,上面写着文本等等--我的想法是使用foreach循环,我没有意识到有矩形,我需要总是改变它们的数量。我怎样才能让它使用foreach,或者可能有其他的方法来做到这一点?下面是我在Swift UI和代码上所做的截图。
VStack(spacing: 32){
HStack(alignment: .center,spacing: 8){
Rectangle()
.frame(width: 24, height: .infinity)
.foregroundColor(Color(red: 0.098, green: 0.303, blue: 0.476))
.padding(.leading, 20)
.padding(.top, 28)
.padding(.bottom, 12)
Rectangle()
.frame(width: 24, height: .infinity)
.foregroundColor(Color(red: 0.098, green: 0.303, blue: 0.476))
.padding(.trailing, 20)
.padding(.top, 28)
.padding(.bottom, 12)
Spacer()
Image("high_volume_blue")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 32, height: 32, alignment: .center)
.padding(.top, 8)
.padding(.trailing, 8)
}
Text(NSLocalizedString("SoundSignals_In_Description_1", comment: ""))
.font(.system(size: 20))
.fontWeight(.light)
.foregroundColor(Color.black)
.multilineTextAlignment(.center)
.padding(.horizontal, 16)
.padding(.bottom, 20)
}
.frame(width: UIScreen.screenWidth - 25, height: .infinity, alignment: .center)
.background(Color.white)这只是白框代码。
谢谢!
发布于 2022-05-01 10:52:22
如果要显示文本视图的列表,可以这样做:
ScrollView {
VStack(alignment: .leading, spacing: 10) {
ForEach(boxes, id: \.self) { box in //Boxes is whatever Array of values you have to display
Text("Write your text here")
.font(.title)
.onTapGesture { } // Also a possibility to tap on each box and execute some functionality
// You can add here more views: Rectangle() or Image() or whatever
}
}
}
.padding(25)
.background(.white)https://stackoverflow.com/questions/71987998
复制相似问题