How to set two line text in SwiftUI ?

For setting up n number of lines of Text in swiftUI we can use .lineLimit(.. function which takes arguments as number of lines.

#For iOS 15 & Below :

we have to set .fixedSize(horizontal: false, vertical: true) & .lineLimit(2)

Text("A two lines TextABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 All alphabates")
    .fixedSize(horizontal: false, vertical: true)
    .lineLimit(2)

# For iOS 16 onwards

Text("A two lines TextABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 All alphabates")     
  .lineLimit(2, reservesSpace: true)

Leave a Comment

Your email address will not be published. Required fields are marked *