Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI - text gets truncated after embedded on a ScrollView

When added a long text inside a text view, it works as expected (not truncated).

Xcode 11.0 beta 6 (11M392q)

import SwiftUI

struct ContentView: View {

    var body: some View {



                Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")

                    .lineLimit(nil)



                }
            }



struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

enter image description here

But when embedded inside a ScrollView, it gets truncated (not expected):

import SwiftUI

struct ContentView: View {

    var body: some View {

        ScrollView {

                Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")

                    .lineLimit(nil)


                   }
                }
            }



struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

enter image description here

I tried setting a .lineLimit(nil) modifier, but also didn't avoid truncating the text.

Is this the expected behaviour for SwiftUI text? Or is it a bug?

Appreciate if someone can help! : )

Cheers

like image 791
Mane Manero Avatar asked Mar 03 '23 12:03

Mane Manero


1 Answers

Text("Your long text goes here")
    .fixedSize(horizontal: false, vertical: true)

should solve the problem.

This is default in iOS 13.1 beta 1 and above.

like image 136
Rudrank Riyam Avatar answered Mar 24 '23 13:03

Rudrank Riyam