iOS Guides | Samples

MonoTouch.UIKit.UIPasteboard Class

Support for the system pasteboard for cut, copy and paste.

See Also: UIPasteboard

Syntax

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

Remarks

Pasteboards

Pasteboards allow information to be shared across applications. The general pasteboard (accessible via the UIPasteboard.General property) is the system-wide pasteboard that applications use by default. Developers can also transfer information across their own applications (those that share their team ID) by creating their own pasteboards.

Setting Pasteboard Data

All operations that set the contents of the pasteboard clear any data that is currently stored there.

To set the pasteboard contents to NSString, NSArray, NSDictionary, NSDate, NSNumber, UIImage or NSUrl use the UIPasteBoard.SetValue method.

To set the pasteboard contents to an image, use the UIPasteBoard.Image. property.

To set the pasteboard contents to a set of images, use the UIPasteBoard.Images. property.

To set the values to arbitrary data types, use the UIPasteBoard.SetData method.

You can use the convenience properties UIPasteboard.String, UIPasteboard.Strings, UIPasteboard.Image, UIPasteboard.Images, UIPasteboard.Url, UIPasteboard.Urls, UIPasteboard.Color and UIPasteboard.Colors to set and get strings, images, Urls or Colors on the pasteboard.

C# Example

//
// Setting the contents of the pasteboard to "Hello World"
// by specifying the UTI type for text.
//
var text = new NSString ("Hello world")
UIPasteboard.General.SetValue (text, MonoTouch.MobileCoreServices.UTType.Text);

// 
// Setting the contents of the pasteboard to "So hello"
// using the convenience property:
//
UIPasteboard.General.String = "So hello";

Pasteboard Types

Whenever possible, you should use an UTI type to set the type of the information that is being stored on the pasteboard. You can find a list of common iOS/Mac UTI types on the UTType type.

UTI types are merely strings separated by dots. For example the UTI type for an image is "public.image". Apple maintains the "public.*" directory of UTI types.

Apple recommends that if you need to use your own data type to use an inverse domain to name them. For example, "com.xamarin.t-shirt-application.sales-information".

Related content

Requirements

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

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

See Also: NSObject

Public Constructors

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

[read-only]
static
AutomaticNSString.
[read-only]
ChangeCountInt32. The number of times this UIPasteBoard's contents have changed. Read-only.
[read-only]
static
ChangedNotificationNSString. Notification constant for Changed
[read-only]
static
ChangedTypesAddedKeyNSString. Represents the value associated with the constant UIPasteboardChangedTypesAddedKey
[read-only]
static
ChangedTypesRemovedKeyNSString. Represents the value associated with the constant UIPasteboardChangedTypesRemovedKey
[read-only]
override
ClassHandleIntPtr. The handle for this class.
ColorUIColor. The color of the first pasteboard item.
ColorsUIColor[]. The colors used by all pasteboard items.
[read-only]
CountInt32. The number of items on this UIPasteBoard. Read-only.
[read-only]
static
GeneralUIPasteboard. The general pasteboard, used for copy-paste operations.
[read-only]
HasColorsBoolean. Gets whether the UIPasteboard.Colors array is non-empty.
[read-only]
HasImagesBoolean. Gets whether the UIPasteboard.Images array is non-empty.
[read-only]
HasStringsBoolean. Gets whether the UIPasteboard.Strings array is non-empty.
[read-only]
HasUrlsBoolean.
ImageUIImage. Retrieves or sets the image of the first pasteboard item.
ImagesUIImage[]. The images of all the pasteboard items.
ItemsNSDictionary[]. The pasteboard items on this UIPasteBoard.
[read-only]
NameString. The name of this UIPasteBoard. Read-only.
PersistentBoolean. Whether this UIPasteBoard is persistent.
[read-only]
static
RemovedNotificationNSString. Notification constant for Removed
StringString. The string value of the first pasteboard item.
StringsString[]. The string values of all the pasteboard items.
[read-only]
static
TypeListColorNSArray. Represents the value associated with the constant UIPasteboardTypeListColor
[read-only]
static
TypeListImageNSArray. Represents the value associated with the constant UIPasteboardTypeListImage
[read-only]
static
TypeListStringNSArray. Represents the value associated with the constant UIPasteboardTypeListString
[read-only]
static
TypeListURLNSArray. Represents the value associated with the constant UIPasteboardTypeListURL
[read-only]
TypesString[]. The representations types of the first item on the pasteboard.
UrlNSUrl. The URL of the first pasteboard item.
UrlsNSUrl[]. The URLs of all the pasteboard items.

Public Methods

AddItems(NSDictionary[])
Appends items to the content of this UIPasteBoard.
Contains(String[]) : Boolean
Whether this UIPasteBoard holds data of the specified type.
Contains(String[], NSIndexSet) : Boolean
Whether the pasteboard elements specified by itemSet contain data of the specified pasteboardTypes.
DataForPasteboardType(String) : NSData
The data on this UIPasteBoard for the specified representation type.
static
FromName(String, Boolean) : UIPasteboard
Returns the UIPasteBoard for the specified name, optionally creating one if it doesn't exist.
GetDataForPasteboardType(String, NSIndexSet) : NSData[]
The data objects in the specified pasteboard items that have the specified representation type.
static
GetUnique() : UIPasteboard
The application pasteboard identified by the unique system-generated name.
GetValue(String) : NSObject
Retrieves data of the specified type.
GetValuesForPasteboardType(String, NSIndexSet) : NSData[]
Returns the objects on this UIPasteBoard that have the specified representation type.
ItemSetWithPasteboardTypes(String[]) : NSIndexSet
A set whose values are the indices of those pasteboard items that have the specified representation type.
PasteBoardTypesForSet(NSIndexSet) : NSArray[]
The representation types for all the items in the specified set.
static
Remove(String)
Removes the specified application pasteboard.
SetData(NSData, String)
Sets the data for the specified representation type in this UIPasteBoard.
SetItems(NSDictionary[], NSDictionary)
Adds items to the pasteboard, identified by the keys in the itemsNSDictionary.
SetItems(NSDictionary[], UIPasteboardOptions)
SetValue(NSObject, String)
Sets the value for the specified representation type in this UIPasteBoard.