UIMenu

https://developer.apple.com/documentation/uikit/uimenu

"A container for grouping related menu elements in an app menu or contextual menu."

앱 메뉴 혹은 contextual 메뉴에 있는 관련 메뉴 요소들을 그룹화하기 위한 컨테이너입니다.

Declaration

@MainActor class UIMenu : UIMenuElement

Overview

앱 디스플레이에서 메뉴 및 하위 메뉴를 설계하기 위해 UIMenu 객체를 생성하고 사용하시기 바랍니다. macOS에서 실행될 때 앱에 메뉴를 제공할 수 있고, 사용자가 명령 키를 누를 때 iPad의 discoverability HUD에서 메뉴에 핵심 명령 요소가 나타나도록 할 수 있습니다. 어떠한 뷰에 대해, 특정 상호작용의 반응으로 contextual 액션을 표시하기 위해서 메뉴를 사용할 수도 있습니다. 모든 메뉴는 제목, 이미지(선택사항), 자식 요소의 집합(선택사항)을 갖습니다. 사용자가 메뉴로부터 요소를 선택하면, 시스템은 개발자가 구현한 코드를 실행합니다.

Listing 1 Adding a menu group containing two menu elements, New and Open, to the File menu

// Ensure that the builder is modifying the menu bar system.
guard builder.system == UIMenuSystem.main else { return }

let newDocument = UIKeyCommand(title: "New",
                               action: #selector(newDocument(_:)),
                               input: "n",
                               modifierFlags: .command)

let openDocument = UIKeyCommand(title: "Open...",
                                action: #selector(openDocument(_:)),
                                input: "o",
                                modifierFlags: .command)

// Use the .displayInline option to avoid displaying the menu as a submenu,
// and to separate it from the other menu elements using a line separator.
let newMenu = UIMenu(title: "", options: .displayInline, children: [newDocument, openDocument])

// Insert menu item at the top of the File menu.
builder.insertChild(newMenu, atStartOfMenu: .file)

UIMenu 사용 바업ㅂ에 대한 예시는 Adding Menus and Shortcuts to the Menu Bar and User Interface를 살펴보시기 바랍니다.

Adding Menus and Shortcuts to the Menu Bar and User Interface
https://developer.apple.com/documentation/uikit/uicommand/adding_menus_and_shortcuts_to_the_menu_bar_and_user_interface

See Also


App Menus

UIMenuSystem

메인 혹은 contextual 메뉴 시스템을 나타내는 객체입니다.

https://developer.apple.com/documentation/uikit/uimenusystem
https://velog.io/@panther222128/UIMenuSystem


좋은 웹페이지 즐겨찾기