Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a SwiftUI equivalent for lineBreakMode for Text views?

Tags:

swiftui

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.

like image 919
Eugene Avatar asked Nov 06 '22 13:11

Eugene


1 Answers

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.

like image 70
Ryan Avatar answered Nov 28 '22 08:11

Ryan