UIBarButtonItem Constructors

Definition

Overloads

UIBarButtonItem()

Default constructor that initializes a new instance of this class with no parameters.

UIBarButtonItem(UIImage, UIBarButtonItemStyle, NSObject, Selector)

Constructor that allows an image and style to be specified, along with a target-action pair.

UIBarButtonItem(String, UIBarButtonItemStyle, NSObject, Selector)

Constructor that allows specifying a title and style for a UIBarButtonItem along with an Objective-C style target-action pair.

UIBarButtonItem(UIImage, UIBarButtonItemStyle, EventHandler)

Constructor that allows a custom image, style and evnet handler to be specied when the button is created.

UIBarButtonItem(UIBarButtonSystemItem, NSObject, Selector)

Constructor that allows a system item along with a target-action pair to be specified.

UIBarButtonItem(String, UIBarButtonItemStyle, EventHandler)

Constructor that allows a title to be specified for display on the button depending on the style used. Also allows an event handler to be specified that will be called when the button is pressed.

UIBarButtonItem(UIImage, UIImage, UIBarButtonItemStyle, NSObject, Selector)

Constructor that allows specifying separate images for landscape and portrait.

UIBarButtonItem(UIView)

Constructor that allows a custom view to be specified for a UIBarButtonItem.

UIBarButtonItem(UIBarButtonSystemItem)

Constructor that allows a particular UIBarButtonSystemItem to be specified when the button is created.

UIBarButtonItem(IntPtr)

A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

UIBarButtonItem(NSObjectFlag)

Constructor to call on derived classes to skip initialization and merely allocate the object.

UIBarButtonItem(NSCoder)

A constructor that initializes the object from the data stored in the unarchiver object.

UIBarButtonItem(UIBarButtonSystemItem, EventHandler)

Constructor that allows a particular UIBarButtonSystemItem to be specified when the button is created along with an event handler.

UIBarButtonItem()

Default constructor that initializes a new instance of this class with no parameters.

[Foundation.Export("init")]
[ObjCRuntime.DesignatedInitializer]
public UIBarButtonItem ();
Attributes

Applies to

UIBarButtonItem(UIImage, UIBarButtonItemStyle, NSObject, Selector)

Constructor that allows an image and style to be specified, along with a target-action pair.

[Foundation.Export("initWithImage:style:target:action:")]
public UIBarButtonItem (UIKit.UIImage image, UIKit.UIBarButtonItemStyle style, Foundation.NSObject target, ObjCRuntime.Selector action);
new UIKit.UIBarButtonItem : UIKit.UIImage * UIKit.UIBarButtonItemStyle * Foundation.NSObject * ObjCRuntime.Selector -> UIKit.UIBarButtonItem

Parameters

image
UIImage

Image to be used in the button. If it is too large, the image is scaled to fit.

This parameter can be null.

style
UIBarButtonItemStyle

A style value defined in UIBarButtonItemStyle.

target
NSObject

An NSObject that will receive the action message.

This parameter can be null.

action
Selector

The action that will be sent to the object specified as the target.

This parameter can be null.

Attributes

Remarks

Alpha values from the source image, ignoring opaque values, are used to create the image that appears on the button.

A target and action are an Objective-C mechanism for allowing a method in some object, the target, to be called for some action. Objective-C uses message sending, where the message includes a selector that equates to the name of the method to call. This is basically another way of handling the button being pressed.

Applies to

UIBarButtonItem(String, UIBarButtonItemStyle, NSObject, Selector)

Constructor that allows specifying a title and style for a UIBarButtonItem along with an Objective-C style target-action pair.

[Foundation.Export("initWithTitle:style:target:action:")]
public UIBarButtonItem (string title, UIKit.UIBarButtonItemStyle style, Foundation.NSObject target, ObjCRuntime.Selector action);
new UIKit.UIBarButtonItem : string * UIKit.UIBarButtonItemStyle * Foundation.NSObject * ObjCRuntime.Selector -> UIKit.UIBarButtonItem

Parameters

title
String

String value used to display the title of the button.

This parameter can be null.

style
UIBarButtonItemStyle

A style value defined in UIBarButtonItemStyle.

target
NSObject

An NSObject that will receive the action message.

This parameter can be null.

action
Selector

The action that will be sent to the object specified as the target.

This parameter can be null.

Attributes

Remarks

A target and action are an Objective-C mechanism for allowing a method in some object, the target, to be called for some action. Objective-C uses message sending, where the message includes a selector that equates to the name of the method to call. This is basically another way of handling the button being pressed.

Applies to

UIBarButtonItem(UIImage, UIBarButtonItemStyle, EventHandler)

Constructor that allows a custom image, style and evnet handler to be specied when the button is created.

public UIBarButtonItem (UIKit.UIImage image, UIKit.UIBarButtonItemStyle style, EventHandler handler);
new UIKit.UIBarButtonItem : UIKit.UIImage * UIKit.UIBarButtonItemStyle * EventHandler -> UIKit.UIBarButtonItem

Parameters

image
UIImage

Image to be used in the button. If it is too large, the image is scaled to fit.

style
UIBarButtonItemStyle

A style value defined in UIBarButtonItemStyle.

handler
EventHandler

The event handler to be called when the button is pressed.

Remarks

Alpha values from the source image, ignoring opaque values, are used to create the image that appears on the button.

Applies to

UIBarButtonItem(UIBarButtonSystemItem, NSObject, Selector)

Constructor that allows a system item along with a target-action pair to be specified.

[Foundation.Export("initWithBarButtonSystemItem:target:action:")]
public UIBarButtonItem (UIKit.UIBarButtonSystemItem systemItem, Foundation.NSObject target, ObjCRuntime.Selector action);
new UIKit.UIBarButtonItem : UIKit.UIBarButtonSystemItem * Foundation.NSObject * ObjCRuntime.Selector -> UIKit.UIBarButtonItem

Parameters

systemItem
UIBarButtonSystemItem

The UIBarButtonSystemItem used to create the button.

target
NSObject

An NSObject that will receive the action message.

This parameter can be null.

action
Selector

The action that will be sent to the object specified as the target.

This parameter can be null.

Attributes

Remarks

A target and action are an Objective-C mechanism for allowing a method in some object, the target, to be called for some action. Objective-C uses message sending, where the message includes a selector that equates to the name of the method to call. This is basically another way of handling the button being pressed.

Applies to

UIBarButtonItem(String, UIBarButtonItemStyle, EventHandler)

Constructor that allows a title to be specified for display on the button depending on the style used. Also allows an event handler to be specified that will be called when the button is pressed.

public UIBarButtonItem (string title, UIKit.UIBarButtonItemStyle style, EventHandler handler);
new UIKit.UIBarButtonItem : string * UIKit.UIBarButtonItemStyle * EventHandler -> UIKit.UIBarButtonItem

Parameters

title
String

String value used to display the title of the button.

style
UIBarButtonItemStyle

A style value defined in UIBarButtonItemStyle.

handler
EventHandler

The event handler to be called when the button is pressed.

Remarks

Some UIBarButtonItemStyle values display the title on the button while others display an image.

Applies to

UIBarButtonItem(UIImage, UIImage, UIBarButtonItemStyle, NSObject, Selector)

Constructor that allows specifying separate images for landscape and portrait.

[Foundation.Export("initWithImage:landscapeImagePhone:style:target:action:")]
public UIBarButtonItem (UIKit.UIImage image, UIKit.UIImage landscapeImagePhone, UIKit.UIBarButtonItemStyle style, Foundation.NSObject target, ObjCRuntime.Selector action);
new UIKit.UIBarButtonItem : UIKit.UIImage * UIKit.UIImage * UIKit.UIBarButtonItemStyle * Foundation.NSObject * ObjCRuntime.Selector -> UIKit.UIBarButtonItem

Parameters

image
UIImage

Image to be used in the button. If it is too large, the image is scaled to fit.

This parameter can be null.

landscapeImagePhone
UIImage

The landscape image to use.

This parameter can be null.

style
UIBarButtonItemStyle

A style value defined in UIBarButtonItemStyle.

target
NSObject

An NSObject that will receive the action message.

This parameter can be null.

action
Selector

The action that will be sent to the object specified as the target.

This parameter can be null.

Attributes

Remarks

The landscape image will be used when the UIUserInterfaceIdiom is Phone.

A target and action are an Objective-C mechanism for allowing a method in some object, the target, to be called for some action. Objective-C uses message sending, where the message includes a selector that equates to the name of the method to call. This is basically another way of handling the button being pressed.

Applies to

UIBarButtonItem(UIView)

Constructor that allows a custom view to be specified for a UIBarButtonItem.

[Foundation.Export("initWithCustomView:")]
public UIBarButtonItem (UIKit.UIView customView);
new UIKit.UIBarButtonItem : UIKit.UIView -> UIKit.UIBarButtonItem

Parameters

customView
UIView

The custom view to use when creating the UIBarButtonItem.

Attributes

Remarks

The custom view allows an arbitray UIView to be used for the UIBarButtonItem.

Applies to

UIBarButtonItem(UIBarButtonSystemItem)

Constructor that allows a particular UIBarButtonSystemItem to be specified when the button is created.

public UIBarButtonItem (UIKit.UIBarButtonSystemItem systemItem);
new UIKit.UIBarButtonItem : UIKit.UIBarButtonSystemItem -> UIKit.UIBarButtonItem

Parameters

systemItem
UIBarButtonSystemItem

The UIBarButtonSystemItem used to create the button.

Remarks

The UIBarButtonSystemItem allows a number of buttons pre-defined by the system to be used when creating a UIBarButtonItem.

Applies to

UIBarButtonItem(IntPtr)

A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

protected internal UIBarButtonItem (IntPtr handle);
new UIKit.UIBarButtonItem : nativeint -> UIKit.UIBarButtonItem

Parameters

handle
IntPtr

nativeint

Pointer (handle) to the unmanaged object.

Remarks

This constructor is invoked by the runtime infrastructure (GetNSObject(IntPtr)) to create a new managed representation for a pointer to an unmanaged Objective-C object. Developers should not invoke this method directly, instead they should call the GetNSObject method as it will prevent two instances of a managed object to point to the same native object.

Applies to

UIBarButtonItem(NSObjectFlag)

Constructor to call on derived classes to skip initialization and merely allocate the object.

protected UIBarButtonItem (Foundation.NSObjectFlag t);
new UIKit.UIBarButtonItem : Foundation.NSObjectFlag -> UIKit.UIBarButtonItem

Parameters

t
NSObjectFlag

Unused sentinel value, pass NSObjectFlag.Empty.

Remarks

This constructor should be called by derived classes when they completely construct the object in managed code and merely want the runtime to allocate and initialize the NSObject. This is required to implement the two-step initialization process that Objective-C uses, the first step is to perform the object allocation, the second step is to initialize the object. When developers invoke the constructor that takes the NSObjectFlag.Empty they take advantage of a direct path that goes all the way up to NSObject to merely allocate the object's memory and bind the Objective-C and C# objects together. The actual initialization of the object is up to the developer.

This constructor is typically used by the binding generator to allocate the object, but prevent the actual initialization to take place. Once the allocation has taken place, the constructor has to initialize the object. With constructors generated by the binding generator this means that it manually invokes one of the "init" methods to initialize the object.

It is the developer's responsibility to completely initialize the object if they chain up using the NSObjectFlag.Empty path.

In general, if the developer's constructor invokes the NSObjectFlag.Empty base implementation, then it should be calling an Objective-C init method. If this is not the case, developers should instead chain to the proper constructor in their class.

The argument value is ignored and merely ensures that the only code that is executed is the construction phase is the basic NSObject allocation and runtime type registration. Typically the chaining would look like this:

//
// The NSObjectFlag merely allocates the object and registers the
// C# class with the Objective-C runtime if necessary, but no actual
// initXxx method is invoked, that is done later in the constructor
//
// This is taken from Xamarin.iOS's source code:
//
[Export ("initWithFrame:")]
public UIView (System.Drawing.RectangleF frame) : base (NSObjectFlag.Empty)
{
// Invoke the init method now.
	var initWithFrame = new Selector ("initWithFrame:").Handle;
	if (IsDirectBinding)
		Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSend_CGRect (this.Handle, initWithFrame, frame);
	else
		Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_CGRect (this.SuperHandle, initWithFrame, frame);
}

Applies to

UIBarButtonItem(NSCoder)

A constructor that initializes the object from the data stored in the unarchiver object.

[Foundation.Export("initWithCoder:")]
[ObjCRuntime.DesignatedInitializer]
public UIBarButtonItem (Foundation.NSCoder coder);
new UIKit.UIBarButtonItem : Foundation.NSCoder -> UIKit.UIBarButtonItem

Parameters

coder
NSCoder

The unarchiver object.

Attributes

Remarks

This constructor is provided to allow the class to be initialized from an unarchiver (for example, during NIB deserialization). This is part of the NSCoding protocol.

If developers want to create a subclass of this object and continue to support deserialization from an archive, they should implement a constructor with an identical signature: taking a single parameter of type NSCoder and decorate it with the [Export("initWithCoder:"] attribute declaration.

The state of this object can also be serialized by using the companion method, EncodeTo.

Applies to

UIBarButtonItem(UIBarButtonSystemItem, EventHandler)

Constructor that allows a particular UIBarButtonSystemItem to be specified when the button is created along with an event handler.

public UIBarButtonItem (UIKit.UIBarButtonSystemItem systemItem, EventHandler handler);
new UIKit.UIBarButtonItem : UIKit.UIBarButtonSystemItem * EventHandler -> UIKit.UIBarButtonItem

Parameters

systemItem
UIBarButtonSystemItem

The UIBarButtonSystemItem used to create the button.

handler
EventHandler

The event handler to be called when the button is pressed.

Remarks

The event handler will be called when the button is pressed.

Applies to