0

以下スクリーンショットの下の囲いのようにButtonとTextを混在させつつ同じ行のように表示させたいのですが、うまくいきまさせん。

LazyVGridなどはGrid数が決まってしまって自由な形で設定することが難しいです。

struct ContentView: View {
  let models: [ViewModel] = [
    .init(text: "text1", type: .text),
    .init(text: "button2", type: .button),
    .init(text: "text2", type: .text),
    .init(text: "button2", type: .button)
  ]

  var body: some View {
    ForEach(models) { model in
      switch model.type {
        case .text: Text(model.text)
        case .button: Button(model.text) { print(model.text) }
      }
    }
  }
}

0

この質問に回答するには、ログインする必要があります。

のタグが付いた他の質問を参照する。