UIResponder.Copy(NSObject) Method

Definition

Indicates a "Copy" editing operation.

[Foundation.Export("copy:")]
public virtual void Copy (Foundation.NSObject sender);
override this.Copy : Foundation.NSObject -> unit

Parameters

sender
NSObject

Object calling this method.

This parameter can be null.

Attributes

Remarks

Applications overriding this method should expose the selected information and pass it to the UIPasteboard.

You can invoke the Copy method to retrieve the contents of the object and have them on the pasteboard, for example:

void MakeCopy (UITextField field)
{
field.Copy (this);
}

The following example shows how to implement the Copy method on your own subclass of UIResponder.

//
// Selectable label: a label that shows the "Copy" menu when the user
// long presses
//
public class SelectableLabel : UILabel {

public SelectableLabel (RectangleF rect) : base (rect)
{
UserInteractionEnabled = true;
var gesture = new UILongPressGestureRecognizer (LongPress);
AddGestureRecognizer (gesture);
}

void LongPress (UILongPressGestureRecognizer r)
{
var location = r.LocationInView (r.View);
var menu = UIMenuController.SharedMenuController;

r.View.BecomeFirstResponder ();

menu.SetTargetRect (r.View.Frame, r.View);
menu.SetMenuVisible (true, true);
}


public override bool CanBecomeFirstResponder { 
get { return true; } 
}

Selector copyAction = new Selector ("copy");

public override bool CanPerform (Selector action, NSObject withSender)
{
if (action == copyAction);
return true;
return false;
}

public override void Copy (NSObject sender)
{
UIPasteboard.General.String = this.Text;
}
}

Applies to