Post

Replies

Boosts

Views

Activity

Reply to Text is truncated with certain font sizes on iOS 17+, but not on iOS 16
I’ve found a workaround that avoids the truncation issue on iOS 18 and later using the new textRenderer(_:) modifier. It ensures that all lines are rendered properly without truncation. @available(iOS 17, *) struct MyTextRenderer: TextRenderer { func draw(layout: Text.Layout, in ctx: inout GraphicsContext) { for line in layout { ctx.draw(line) } } } extension View { @ViewBuilder func avoidTextTruncationBug() -> some View { if #available(iOS 18, *) { textRenderer(MyTextRenderer()) } else { self } } } struct MessageTextView: View { var text: String var body: some View { Text(text) .fixedSize(horizontal: false, vertical: true) .font(.body) .padding(.leading, 16) .padding(.trailing, 16) .padding(.top, 8) .padding(.bottom, 8) .avoidTextTruncationBug() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’25
Reply to Text is truncated with certain font sizes on iOS 17+, but not on iOS 16
Thank you! You’re right — the Spacer()s themselves are not strictly necessary. However, I do need to apply trailing padding and align the text to the leading edge. I tried removing the Spacer() and simplifying the layout, but the issue still reproduces with the following code: HStack { MessageTextView(text: sampleText1) .layoutPriority(100) .padding(.trailing, 20) .frame(maxWidth: .infinity) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’25