Member-only story
SwiftUI ContextMenu and Menu for iOS
ContextMenu
and Menu
can be both used to display quick actions. Context menus can be used, to add actions to an object, for example an image, and menus are more for view wide actions, like changing list filters. Both look nearly the same, but context menus enlarge the object and blur the background. while menus just cast a shadow. Context menus can be toggled by a long press, menus by a simple tap. In this article, I will explain when to use them, how to use them and what you can do with them.
ContextMenu
Context menus add quick actions to a specific object. For example you can add a share action to an image. Or delete, open and info to a file. Through the long press, the user gets extra options. You can display information with the context menu, like file size, but it should mainly be used for actions.
Now, when the image is long pressed, it gives an extra option to save the image. The ContextMenu {}
is not necessary, you can just put the buttons in the .contextMenu()
. You can define an Image
and a Text
, to create the context menu row, so with SwiftUI 2 you…