iOS Guides | Samples

MonoTouch.UIKit.UIMenuController Class

The class used to implement Cut, Copy, Paste, Select, and Delete commands.

See Also: UIMenuController


[MonoTouch.Foundation.Register("UIMenuController", true)]
[MonoTouch.ObjCRuntime.Unavailable(MonoTouch.ObjCRuntime.PlatformName.TvOS, MonoTouch.ObjCRuntime.PlatformArchitecture.All, null)]
public class UIMenuController : NSObject


The UIMenuController is a singleton object, accessed by UIMenuController.SharedMenuController. It manages the editng menu, which provides options for Cut, Copy, Paste, Select, Select All, and Delete commands. The menu is visually associated with a target rectangle specified by UIMenuController.SetTargetRect. It is the application developer's responsibility to set this target rectangle appropriately before displaying the UIMenuController.

The application can add or delete additional menu items using the UIMenuController.MenuItems. The following code, taken from the "Touches Gesture Recognizers" sample shows the code necessary to create a modified context menu:

C# Example

void Setup ()
     var menuController = UIMenuController.SharedMenuController;
     var resetMenuItem = new UIMenuItem ("Reset", new Selector ("ResetImage"));
     var location = gestureRecognizer.LocationInView (gestureRecognizer.View);
     BecomeFirstResponder ();
     menuController.MenuItems = new [] { resetMenuItem };
     menuController.SetTargetRect (new RectangleF (location.X, location.Y, 0, 0), gestureRecognizer.View);
     menuController.MenuVisible = true;
     menuController.Animated = true;
     imageForReset = gestureRecognizer.View;

void ResetImage (UIMenuController controller)
     var mid = new PointF ((imageForReset.Bounds.Left + imageForReset.Bounds.Right) / 2, (imageForReset.Bounds.Top + imageForReset.Bounds.Bottom) / 2);
     var locationInSuperview = imageForReset.ConvertPointToView (mid, imageForReset.Superview);
     imageForReset.Layer.AnchorPoint = new PointF (0.5f, 0.5f);
     imageForReset.Center =locationInSuperview;
     UIView.BeginAnimations (null, IntPtr.Zero);
     imageForReset.Transform = MonoTouch.CoreGraphics.CGAffineTransform.MakeIdentity ();
     UIView.CommitAnimations ();

Related content


Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions:

The members of MonoTouch.UIKit.UIMenuController are listed below.

See Also: NSObject

Public Constructors

Default constructor that initializes a new instance of this class with no parameters.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

ArrowDirectionUIMenuControllerArrowDirection. The direction in which the arrow of the editing menu is pointed.
ClassHandleIntPtr. The handle for this class.
DidHideMenuNotificationNSString. Notification constant for DidHideMenu
DidShowMenuNotificationNSString. Notification constant for DidShowMenu
MenuFrameRectangleF. The RectangleF of the frame of the editing menu. Read-only.
MenuFrameDidChangeNotificationNSString. Notification constant for MenuFrameDidChange
MenuItemsUIMenuItem[]. The custom menu items for the editing menu.
MenuVisibleBoolean. Whether the editing menu is visible.
SharedMenuControllerUIMenuController. The singleton UIMenuController.
WillHideMenuNotificationNSString. Notification constant for WillHideMenu
WillShowMenuNotificationNSString. Notification constant for WillShowMenu

Public Methods

SetMenuVisible(Boolean, Boolean)
Displays or hides the editing menu menu.
SetTargetRect(RectangleF, UIView)
Sets the area in a UIView above or below which the editing menu is positioned.
Updates the appearance and enabled state of menu commands.