title: In SwiftUI, how do I create a dynamic rectangle for a bar chart?
body: <p>I'm trying to create a custom percentage bar chart like the one below </p>
  
  <p><a href="https://i.stack.imgur.com/YuzBJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YuzBJ.png" alt="enter image description here"></a></p>
  
  <p>however, I'm unable to set the bar width programmatically, what am I doing wrong?</p>
  
  <p>Setting .frame(width: UIScreen.main.bounds.width * percent, height:23) produces the following error : Ambiguous reference to member 'frame(width:height:alignment:)'</p>
  
  <pre><code>import SwiftUI
  
  struct BarChartView : View {
      @Binding var percent: Float
  
      init(percentage: Binding&lt;Float&gt;){
          self._percent = percentage
      }
  
      var body: some View {
  
              ZStack {
                  Rectangle().fill(Color.yellow).frame(height: 30).border(Color.black, width:1)
                  HStack {
                          RoundedRectangle(cornerRadius: 5)
                              .fill(Color.green).frame(width: 300, height:23).padding(2)
                      Spacer()
                  }
  
                  HStack {
                      Text("Bar Chart View").padding (2)
                      Spacer()
                      Text("\(String(format: "%02.f", arguments: [self.percent]))%")
                  }
  
              }
          }
  
  }
  </code></pre>
  
  <p>Is there a way to determine the width of the first rectangle in the ZStack and calc a percentage off of that. I would like this to automatically update in landscape mode too, if possible.</p>