Skip to content

UIMenu Controller

Roman Babenko edited this page Jul 1, 2020 · 2 revisions

The native iOS menu interface for the Cut, Copy, Paste, Select, Select All, and Delete commands.

We have ISN_UIMenuController in UIKit for accessing this functionality. You can access it through SharedMenuController instance.

using SA.iOS.UIKit;
This shared instance gives access to the native UIMenuController shared controller that referred to as the editing menu. You can provide your own menu items via the MenuItems property of ISN_UIMenuController.
var menuItems = new List<string> { "Button 1", "Button 2", "Button 3" };
ISN_UIMenuController.SharedMenuController.MenuItems = menuItems;
Then you need to make this menu visible, by calling ShowMenuFromPosition method. UIMenuController positions it relative to a target position that you set in this method by setting float xPos and float yPos.
var xPos = target.x;
var yPos = target.y;

ISN_UIMenuController.SharedMenuController.ShowMenuFromPosition(xPos, yPos, result => 
{
    if (menuItems.Count > result.ChosenIndex) 
    {
        var chosenItem = menuItems[result.ChosenIndex];
        Debug.Log("User picked item " + chosenItem + " at position " + result.ChosenIndex);
    }
});
When user will pick some menuItem it return ChosenIndex of this item. The menu appears above the target position rectangle or if there is not enough space for it, below it. The menu’s pointer is placed at the center of the top or bottom of the target position, as appropriate.

About

Foundation

AV Foundation

App Tracking Transparency

Game Kit

Store Kit

UI Kit

Social

Replay Kit

Contacts

AVKit

Photos

App Delegate

User Notifications

MediaPlayer

Core Location

AdSupport

EventKit

CloudKit

Authentication Services

XCode

Knowledge Base

Clone this wiki locally