SwiftUI Text: How to always show the last characters of a text even if the text is too long?

822 Views Asked by At

I have a text in a frame that can become too long depending on the user input. If a text is too long in SwiftUI, SwiftUI abbreviates it with "..." at the end. Example:

"That's a very long te..."

But now I want the last x characters to always be displayed, even if the text is too long. A good example of my wish is XCode itself:

Example

I'd be happy for help.

1

There are 1 best solutions below

0
On

Use truncationMode(_:)

Example from link above, with .middle mode:

Text("This is a block of text that will show up in a text element as multiple lines. The text will fill the available space, and then, eventually, be truncated.")
    .frame(width: 150, height: 150)
    .truncationMode(.middle)