I have a LazyVGrid with items in it, I don't have any padding on the items because I prefer to let the layout of the LazyVGrid manage the spacing between cells. but when I open the context menu on the item it displays the item as it is with no padding.
how can I tell the context menu to show the preview with added padding around the cell?
In iOS 16 and higher, the contextMenu
modifier takes a preview argument that is of type some View
.
This view could have padding, or a customised Image
. To get padding to work, you might need to wrap the views and padding in a parent view at the top of the hierarchy.
You haven’t shared your code so I can’t give you an example in your context, but it could look like this:
struct MyView: View {
var body: some View {
Text("Example")
.contextMenu {
// Context menu stuff
} preview: {
// Preview here
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With