Environment: macOS 11.0 beta 2, Xcode 12.0 beta 2.
I want to display a long Text inside a List with multiple lines without truncation. Here's my code:
This code does the thing I want (multiline text) on iOS, but on macOS, the text is only a single line and truncated. You can paste this code into a playground to try it out.
If I replace the List with VStack, the text is rendered in multiple lines, so it seems List on macOS disables this behavior.
Here are a few modifiers I tried, but none achieves my desired result:
I want to display a long Text inside a List with multiple lines without truncation. Here's my code:
Code Block swift import PlaygroundSupport import SwiftUI struct ContentView: View { var body: some View { List { Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") } } } let view = ContentView() .frame(width: 250) PlaygroundPage.current.setLiveView(view)
This code does the thing I want (multiline text) on iOS, but on macOS, the text is only a single line and truncated. You can paste this code into a playground to try it out.
If I replace the List with VStack, the text is rendered in multiple lines, so it seems List on macOS disables this behavior.
Here are a few modifiers I tried, but none achieves my desired result:
Code Block swift Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") .lineLimit(nil) .multilineTextAlignment(.leading)
Code Block swift Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") .fixedSize(horizontal: false, vertical: true)
Code Block swift Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") .frame(idealHeight: .infinity)
Code Block swift Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") .frame(idealHeight: .greatestFiniteMagnitude)