Context
I am currently working with the new SwiftUI ContextMenu
, which supports a Preview
. However, I have difficulties forcing the Preview
to take up the full width of the screen.
Code
Text("Hello World")
.contextMenu { menuItems } preview: { Text("Preview") }
Question
Please Note: I already tried to add
.frame(maxWidth: .infinity)
toText("Preview")
but this didn’t solve the problem.
- How can I force the Preview to take up the full width of the screen?
2
Answers
This was deprecated.
You didn’t give much code, so I used random example:
You can use Menu like this:
You could wrap your preview view in a
NavigationStack
. That’s easy, but it will not only expand the preview horizontally, it will also expand vertically, which may not be what you’re looking for.Another way would be to set the
idealWidth
for the preview: