Search code examples
swiftuiview

Text going off the view


When I have a long line of text such as this: SpaceX completed its fourth operational commercial crew mission to the International Space Station Oct. 14 with the safe return of a Crew Dragon spacecraft with four American and European astronauts on board. The text will fall off of the screen, looking at photo 2 below. I've tried to restrain it, but then I get the ... and cannot see the rest of the text, the first image that I had included.

Here is the code:

VStack {
    Text("SpaceX completed its fourth operational commercial crew mission to the International Space Station Oct. 14 with the safe return of a Crew Dragon spacecraft with four American and European astronauts on board.")
        .padding()
}

text trails off the screen

text gets cut off by the screen


Solution

  • The same phenomenon cannot be reproduced through the code example you gave us. Maybe it's causing problems in other parts of your project.

    The solution I thought of is to limit the width of Frame of VStack or Text by the size of the screen to prevent it from leaving.

            VStack {
                Text("SpaceX completed its fourth operational commercial crew mission to the International Space Station Oct. 14 with the safe return of a Crew Dragon spacecraft with four American and European astronauts on board.")
                    .padding()
            }
            .frame(width: UIScreen.main.bounds.width)