【问题标题】:Can i put multiple text lines in a single list section in SwiftUI?我可以在 SwiftUI 的单个列表部分中放置多个文本行吗?
【发布时间】:2020-04-01 14:46:36
【问题描述】:

我想将多行文本放在列表的一个部分(在第一个分隔符之前)。问题是添加的任何新文本都有自己的新行。

我有什么办法可以在一个列表部分中放置多行?这是我的代码:

struct ChestWorkouts: View {
@State var BPWeight: String = ""
@State var GoalBPWeight: String = ""
var body: some View {
    List{
        Text("Bench Press").fontWeight(.bold)
        TextField("Goal Weight", text: $GoalBPWeight).keyboardType(.numberPad)
        TextField("Weight", text: $BPWeight).keyboardType(.numberPad)

    }.environment(\.defaultMinListRowHeight, 90)

【问题讨论】:

    标签: swift xcode swiftui


    【解决方案1】:

    你可以把它们放在VStack

    struct ContentView: View {
        @State var BPWeight: String = ""
        @State var GoalBPWeight: String = ""
        var body: some View {
            List{
                VStack {
                    Text("Bench Press").fontWeight(.bold)
                    TextField("Goal Weight", text: $GoalBPWeight).keyboardType(.numberPad)
                    TextField("Weight", text: $BPWeight).keyboardType(.numberPad)
                }
            }.environment(\.defaultMinListRowHeight, 90)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2016-05-09
      • 2020-11-07
      • 2012-06-21
      • 1970-01-01
      相关资源
      最近更新 更多