11

I have a Text view, and I would like to configure it to wrap the first character that doesn't fit. In UIKit, this would be the equivalent of setting label.lineBreakMode = .byCharWrapping. Has this been implemented for SwiftUI Text yet? I haven't been able to find anything in the documentation for Text.

The reason that I want to do this is that I'm displaying a long code to the user, so wrapping by character rather than by word is desirable.

Eugene
  • 3,417
  • 5
  • 25
  • 49

1 Answers1

2

Not sure if this helps, but I am using the following which leads to long words getting wrapped by characters:

Text("Supercallifragilisticexpialidocious")
    .font(.system(size: 100))
    .minimumScaleFactor(0.01)
    .lineLimit(3)
    .multilineTextAlignment(.leading)

Unfortunately for my use case, I do not want the Text to wrap by characters. If I set lineLimit(1) that works fine and the font size is reduced to keep the Text on 1 line. But if Text is multiple words such as Text("Practically perfect in every way") then I want the string wrapped by word. I can't seem to get both Word wrapping for multiple words and font scaling for long words.

Ryan
  • 10,798
  • 11
  • 46
  • 60
  • 1
    I was having an issue that if using lineLimit(1), if the device was rotate the Text would become the minimum size. If you update the Text, then it expands back to correct full size. To solve this, if you wrap the Text in a do-nothing GeometryReader, that fixes the issue. – Ryan Nov 08 '19 at 06:42