Text Max Character Number SwiftUI

Hi,

Some times long text damage the design of views it might go to a second row and increase view height and damage the overall design, so how to solve this issue, is there a way to set a Max Characters number for Text and TextField views in SwiftUI ? and maybe show few dots as used in some designs ?

Kind Regards

Answered by Claude31 in 803657022

Did you set a frame for the Text or TextField ?

And use truncationMode

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(.tail)

Did you set a frame for the Text or TextField ?

And use truncationMode

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(.tail)
Text Max Character Number SwiftUI
 
 
Q