Hi!
I have a multi-line string I'd like to display as text in a long-press preview (using .contextMenu
). However, text after 3rd or 4th linebreak (\n
) gets clipped. The intended effect is to have the minimum preview size that can fit all of the text.
Tried .frame(maxWidth: .infinity, maxHeight: .infinity)
on Text()
but it didn't have any effect. The only modifier that somewhat works is .containerRelativeFrame([.horizontal, .vertical])
but this gives the maximum preview size, instead of minimum. Any suggestions? TIA.
struct RedditView: View {
@State private var text = "AAAAAAAAAAAAAAAAAAAAAA?\n\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\nCCCCCCCCCCCCCCCCCCCCCCCCCC"
var body: some View {
Text("Long press this")
.frame(width: 300, height: 100)
.contentShape(.rect)
.border(Color.blue)
.contextMenu(menuItems: {
Button {
// do something
} label: {
Label {
Text("Edit")
} icon: {
Image(systemName: "pencil")
}
}
}, preview: {
Text(text)
// .frame(maxWidth: .infinity, maxHeight: .infinity)
.multilineTextAlignment(.center)
.padding()
//.containerRelativeFrame([.horizontal, .vertical])
}
)
}
}