Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyphenation SwiftUI Text

How can I add hyphenation to a SwiftUI Text? Currently SwiftUI makes a paragraph when there is no space, but this makes everything hard to read and messy.

enter image description here

I have done a bit of research and it seems that there is no native method. Is there another way to achieve this?

like image 923
J-- Avatar asked Jun 30 '26 06:06

J--


1 Answers

A possible approach is to add explicitly "soft hyphen" unicode symbols in places where you want hyphenation.

Here is a demo. Prepared with Xcode 12.4 / iOS 14.4

Case 1: enough space

Text("Minded­­­\u{AD}ness")
    .frame(width: 180)        // << wide frame
    .border(Color.black)

enter image description here

Case 2: limited space

Text("Minded­­­\u{AD}ness")
    .frame(width: 80)        // << limited frame
    .border(Color.black)

demo2

Note: Preview does not understand such unicode symbols, so test on Simulator or real device

like image 116
Asperi Avatar answered Jul 03 '26 08:07

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!