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.

The iPhone 15 screen is big enough. Adding a ScrollView doesn't fix this. The problem isn't that there's not enough size being proposed / available to the Text. The problem is that Text internally calculates the needed number of lines wrongly and then takes on a size with a slightly too small height.

I agree with your assessment that the issue is a bug on Text. I saw a similar issue in an app with larger text block, and wrapping the Text with ScrollView had the Text expand to the size a bit higher than the height it calculates, which happened to fix the issue. I can't reproduce the issue your described with my iPhone 15 Simulator + iOS 26.4 (23E244), and so can't verify if the workaround helps in your case, but good to know that it doesn't.

In this situation, the only thing I can see is to switch to UITextView + UIViewRepresentable, which is not a pure SwiftUI way and is probably not your choice.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

The first sample didn't reproduce on the simulator or device without an accessibility override, which I had active on my device, but forgot.

The second sample always reproduces on an iPhone 15 device / sim with affected iOS. Did you test also with this second sample or only the sample code from the initial post?

For an iPhone 15 sim the following OS give these results:

  • 17.5 works
  • 18.6 truncates
  • 26.4 truncates
  • 26.5 truncates

So it's likely an iOS 18.x regression. To pinpoint this more it would be necessary to download more iOS 18 SDKs.

Regarding devices it seems to need a device with 2556x1179 resolution. So an iPhone 16 also reproduces this issue.

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

Whether you wrap that ContentView in a ScrollView or not doesn't affect the truncation in my tests. In our main app this is part of an UICollectionView so also scrollable and it's embedded via a UICollectionViewCell and hosted content configuration.

As the long text is an important UI for our app we have no choice, but to try working around with UIKit UILabel / UITextView embedded as representable.

This is interesting, thanks for your input @DTS Engineer

@kai_ ,

When I test your latest code snippet, the text does not truncate for me on an iPhone 15, 16, or 17 simulator running iOS 17 - iOS 26.

When I compare our view debugger screenshots sent above, I can see your content margins appear to have more padding then what I'm seeing in my Xcode.

What version of Xcode and macOS are you using, and are you able to share the Xcode project file here?

In our main app this is part of an UICollectionView

To confirm, you see the same result outside of a UIViewRepresentable as well?

Thanks!

 Travis

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