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


