title: SwiftUI scale text to fit the width and height
body: <p>I have several rectangles and above each rectangle, there are texts.</p>
  <p><a href="https://i.stack.imgur.com/zZwIq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zZwIq.png" alt="rectangles with text" /></a></p>
  <p>Now, these rectangles are dynamic: they can be very big, or very small depending on the Geometry Reader.</p>
  <p>My issue is that I can't make the text scale bigger or smaller according to the size of the rectangles.</p>
  <p>This is my example code:</p>
  <p>I declare an array of numbers:</p>
  <pre><code>var array: [[Int]] = [
      [4,5,6],
      [3,4,9,6],
      [4,7],
      [1,2,3],
      [1,5,5],
      [1,2,4,5,6]]
  </code></pre>
  <p>and this is the body:</p>
  <pre><code>    GeometryReader { geo in
          HStack(spacing: 0) {
  
              ForEach(0..&lt;6, id: \.self) { i in
  
                  ZStack(alignment: .bottom) {
  
                      LinearGradient(gradient: Gradient(colors: [Color.gray, Color.white]), startPoint: .bottom, endPoint: .top)
                          .frame(width: (geo.size.width - 90) / CGFloat(10), height: 90)
                          .overlay(Rectangle().stroke(Color.white))
                          .cornerRadius(8)
  
                      VStack(spacing: 0) {
                          ForEach(0..&lt;self.array[i].count) { j in
                              Text(&quot;\(self.array[i][j])&quot;).font(.footnote)  
                          }
                      }
                  }
              }
          }
      }
  </code></pre>
  <p><strong>This is what I tried:</strong></p>
  <p>I set the size to be extremely big and the scale factor very small:</p>
  <pre><code>Text(&quot;\(self.array[i][j])&quot;).font(.system(size: 1000)).minimumScaleFactor(0.0005)
  </code></pre>
  <p>I also tried using fixed-size:</p>
  <pre><code>.fixedSize(horizontal: false, vertical: false)
  </code></pre>
  <p>and also this line:</p>
  <pre><code>.allowsTightening(true)
  </code></pre>