SwiftUI Text rendering with too small height / one line missing causing unexpected text truncation on iPhone devices

FB: FB22577211

The following trivial SwiftUI Text rendering causes wrong text layout and truncated text. The text should take the required height to render the text without truncation. Adding fixedSize does also not solve this. This bug only happens on devices and not on the simulator. Confirmed with iPhone 15 and iOS 26.4.1 but my colleague used another iPhone so it’s multiple iPhone devices.

import SwiftUI

let txt = """
  Es sollte die erste Japan-Tournee von vielen werden, kein anderes Land – abgesehen von Österreich und der Schweiz – bereisten die Berliner Philharmoniker häufiger. Wie kam es zu dem überschäumend herzlichen Empfang, der dem Orchester bei seinem ersten Gastspiel in Tokio bereitet wurde und wie wurde das Land zu einer »zweiten Heimat« für die Berliner? Ein konkreter historischer Grundstein für das hohe Ansehen klassischer Musik »made in Germany« in Japan wurde bereits im 19. Jahrhunderts gelegt: Als Teil von umfassenden gesellschaftlichen Modernisierungsmaßnahmen vergab die Regierung ab 1868 Stipendien an junge japanische Intellektuelle, damit diese an den besten internationalen Instituten studieren konnten. Berlin wurde – neben Wien – als globales Zentrum der Musik betrachtet, und so erhielten viele japanische Studierende um die Jahrhundertwende die Gelegenheit, von Komponisten wie etwa Max Bruch zu lernen. Zurück in der Heimat, teilten sie ihre Begeisterung für die europäische Kunstmusik sowie das Wissen um die instrumentale und kompositorische Praxis der klassisch-romantischen Tradition.
  """

struct ContentView: View {
    var body: some View {
        VStack {
            Text(txt)
        }
        .padding(.leading, 20)
        .padding(.trailing, 20)
        .frame(maxWidth: .infinity)
    }
}

This is also enough:

Text(txt)
        .padding(.horizontal, 20)
        .fixedSize(horizontal: false, vertical: true)

Expected:

  • Text is rendered without truncation / ellipsis.

Actual:

  • Text is rendered with too small height / missing one line so it’s truncated / with ellipsis.

Hello @kai_,

Your sample code uses a standard font which will adapt to the users selected font size.

iOS provides a wide range of text sizes for the user to select from. Build your app to be accessible to users who select a different text size.

For more information see Typography and Font.

When I run your code on an iPhone 15 with 26.4, I can see the full text. It seems the size of the text in your environment does not fit within its content margins.

To see these margins, try using Xcode's Debug View Hierarchy feature.

Take look at these margins and resource, let me know what you find.

 Travis

Thank you for the reply Travis.

I know the view debugger, but I didn't see anything interesting there. A screenshot is below.

However, your mention of Typography was a good hint. I actually had an accessibility font active on my iPhone device, but forgot about that. Note that this sample app is extracted from a bigger app, where we run into this issue where there's no dynamic type support. I also confirmed that changing the accessibility font size doesn't change the bug or font in the main app. With my sample I confirmed this happens with the default font / Font.body and DynamicTypeSize.medium. With that I can now also reproduce the issue in the iPhone simulator.

struct ContentView: View {
    var body: some View {
      Text(txt)
        .dynamicTypeSize(.medium)
        .fixedSize(horizontal: false, vertical: true)
        .padding(.horizontal, 20)
        .frame(maxHeight: .infinity)
    }
}

View Debugger iPhone device screenshot

View Debugger iPhone sim screenshot

Yeah, this looks like a bug in SwiftUI Text, and so thanks for filing the feedback report. Not sure if this is appropriate to your UI, but as a potential workaround, you can try to wrap your Text with ScrollView, which I believe should give the Text enough space and avoid the truncation.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

SwiftUI Text rendering with too small height / one line missing causing unexpected text truncation on iPhone devices
 
 
Q