2

I have the following component:

Text(booking.endDate!, style: .relative)
                    .font(.system(.title, design: .rounded))
                    .foregroundColor(Color(.jpGreen))
                    .fixedSize(horizontal: true, vertical: false)

This is a countdown to a date formatted as hours and minutes, however in the interface it is randomly truncated at irregular intervals such as this

enter image description here

If i have applied fixed size attributes, how can i go further to make it never truncate?

jwarris91
  • 902
  • 9
  • 24
  • Does this answer your question? [How to scale text to fit parent view with SwiftUI?](https://stackoverflow.com/questions/57035746/how-to-scale-text-to-fit-parent-view-with-swiftui) – Aleksey Potapov Jun 25 '20 at 14:42
  • Not reproducible with Xcode 12 with just code snapshot in ContentView. Would you give more context? – Asperi Jun 25 '20 at 14:44
  • its in a VStack and theres 2 VStack in an HStack, if that helps, im brand new to swiftui so unsure what info is needed – jwarris91 Jun 25 '20 at 14:51

2 Answers2

2

You can avoid this by adding .allowsTightening(true) to your text.

Applying it may not even fully work depending on just how much space can be tightened.

Source : Mark Moeykens's book

EDIT: Also you can allow SwiftUI to scale your text to fit the available space.

Try using minimumScaleFactor for example, it takes a value between 0 and 1.

Hadi
  • 1,294
  • 1
  • 8
  • 8
0

How about simply add .padding(.horizontal) to the end just like this.

Text("...").padding(.horizontal)