title: How to get SwiftUI Text to clip instead of truncate with dots (...)
body: <p>In a SwiftUI view, I have several <code>Text</code> elements in a <code>HStack</code>. Depending on the user input there will not be horizontal room to show all of the texts. The <code>HStack</code> does it job fine by ensuring all of the <code>Text</code> elements get equal widths and the strings are truncated. This is all as expected and as it should be.</p>
  <p>The problem is that all the strings are truncated with a &quot;...&quot; in the end whereas I want the behaviour of <code>UILabel.lineBreakMode = .byClipping</code>, that is the string should simply be cut off at the edge of the <code>Text</code> element.</p>
  <p>How do I achieve this?</p>
  <p>Edit for more details on what I want:</p>
  <pre><code>import SwiftUI
  
  struct TextClipPoC: View {
      var body: some View {
          HStack {
              textElm
              textElm
              textElm
              textElm
          }
      }
  
      var textElm: some View {
          Text(&quot;abcdefghijklmn&quot;)
              .padding(.all, 3)
              .background(Color.yellow)
      }
  }
  
  struct TextClipPoC_Previews: PreviewProvider {
      static var previews: some View {
          TextClipPoC()
              .previewLayout(.fixed(width: 320, height: 40))
      }
  }
  </code></pre>
  <p>gives this output:
  <a href="https://i.stack.imgur.com/jg56I.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jg56I.png" alt="Default truncating behaviour" /></a></p>
  <p>I want the exact same output as above, except instead of &quot;...&quot; I want the text to just clip.</p>
  <p>If I just add <code>.fixedSize()</code> to the <code>HStack</code> (or to the <code>Text</code> elements), as suggested in a solution, I get this result:
  <a href="https://i.stack.imgur.com/gD6vT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gD6vT.png" alt="With fixed with" /></a></p>