title: SwiftUI: how to size to fit a Button to expand to fill a VStack or HStack parent View?
body: <p>I am trying to create 2 buttons that are equal width, positioned one above the other, vertically. It should look like this:</p>
  
  <p><a href="https://i.stack.imgur.com/T9xs2.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/T9xs2.jpg" alt="Two equal-width buttons positioned vertically with space between them"></a></p>
  
  <p>I have placed 2 <code>Buttons</code> inside a <code>VStack</code> which automatically expands to the width of the larger button. What I am trying to do is have the width of the buttons expand to fill the width of the <code>VStack</code>, but this is what I get instead:</p>
  
  <p><a href="https://i.stack.imgur.com/DxZNz.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/DxZNz.jpg" alt="VStack auto sizing to largest button"></a></p>
  
  <pre><code>VStack(alignment: .center, spacing: 20) {
  
      NavigationLink(destination: CustomView()) {
          Text("Button")
      }.frame(height: 44)
          .background(Color.primary)
  
      Button(action: { self.isShowingAlert = true }) {
          Text("Another Button")
      }.frame(height: 44)
          .background(Color.primary)
  
  }.background(Color.secondary)
  </code></pre>
  
  <p>Setting the width of the <code>VStack</code> expands it, but the buttons do not expand to fit:</p>
  
  <pre><code>VStack(alignment: .center, spacing: 20) {
      ...
  }.frame(width: 320)
      .background(Color.secondary)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RBvQ8.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/RBvQ8.jpg" alt="VStack width expands but Buttons do not"></a></p>
  
  <p>So my question is:</p>
  
  <p><strong>Is there a way to do this, besides manually setting the frame of every item in my layout?</strong></p>
  
  <p>I would rather not have to specify each one as it will become difficult to manage.</p>