Share via


UIBarButtonItem Constructors

Definition

Overloads

Name Description
UIBarButtonItem()

Creates a new UIBarButtonItem with default values.

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

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

UIBarButtonItem(UIBarButtonSystemItem, UIAction, UIMenu)
UIBarButtonItem(UIBarButtonSystemItem, NSObject, Selector)
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, UIMenu)
UIBarButtonItem(UIBarButtonSystemItem, UIMenu)
UIBarButtonItem(String, UIImage, NSObject, Selector, UIMenu)
UIBarButtonItem(UIBarButtonSystemItem, UIAction)
UIBarButtonItem(UIAction, UIMenu)
UIBarButtonItem(String, UIMenu)
UIBarButtonItem(UIView)
UIBarButtonItem(UIBarButtonSystemItem)

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

UIBarButtonItem(UIAction)
UIBarButtonItem(NativeHandle)

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(UIImage, UIImage, UIBarButtonItemStyle, NSObject, Selector)

UIBarButtonItem()

Creates a new UIBarButtonItem with default values.

[Foundation.Export("init")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
[ObjCRuntime.DesignatedInitializer]
public UIBarButtonItem();
Attributes

Applies to

UIBarButtonItem(UIImage, UIBarButtonItemStyle, NSObject, Selector)

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

Parameters

image
UIImage
target
NSObject
action
Selector
Attributes

Applies to

UIBarButtonItem(String, UIBarButtonItemStyle, NSObject, Selector)

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

Parameters

title
String
target
NSObject
action
Selector
Attributes

Applies to

UIBarButtonItem(UIImage, UIBarButtonItemStyle, EventHandler)

Constructor that allows a custom image, style and event 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, UIAction, UIMenu)

[Foundation.Export("initWithBarButtonSystemItem:primaryAction:menu:")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public UIBarButtonItem(UIKit.UIBarButtonSystemItem systemItem, UIKit.UIAction? primaryAction, UIKit.UIMenu? menu);
[<Foundation.Export("initWithBarButtonSystemItem:primaryAction:menu:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : UIKit.UIBarButtonSystemItem * UIKit.UIAction * UIKit.UIMenu -> UIKit.UIBarButtonItem

Parameters

primaryAction
UIAction
menu
UIMenu
Attributes

Applies to

UIBarButtonItem(UIBarButtonSystemItem, NSObject, Selector)

[Foundation.Export("initWithBarButtonSystemItem:target:action:")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public UIBarButtonItem(UIKit.UIBarButtonSystemItem systemItem, Foundation.NSObject? target, ObjCRuntime.Selector? action);
[<Foundation.Export("initWithBarButtonSystemItem:target:action:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : UIKit.UIBarButtonSystemItem * Foundation.NSObject * ObjCRuntime.Selector -> UIKit.UIBarButtonItem

Parameters

target
NSObject
action
Selector
Attributes

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, UIMenu)

[Foundation.Export("initWithImage:menu:")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public UIBarButtonItem(UIKit.UIImage? image, UIKit.UIMenu? menu);
[<Foundation.Export("initWithImage:menu:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : UIKit.UIImage * UIKit.UIMenu -> UIKit.UIBarButtonItem

Parameters

image
UIImage
menu
UIMenu
Attributes

Applies to

UIBarButtonItem(UIBarButtonSystemItem, UIMenu)

[Foundation.Export("initWithBarButtonSystemItem:menu:")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public UIBarButtonItem(UIKit.UIBarButtonSystemItem systemItem, UIKit.UIMenu? menu);
[<Foundation.Export("initWithBarButtonSystemItem:menu:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : UIKit.UIBarButtonSystemItem * UIKit.UIMenu -> UIKit.UIBarButtonItem

Parameters

menu
UIMenu
Attributes

Applies to

UIBarButtonItem(String, UIImage, NSObject, Selector, UIMenu)

[Foundation.Export("initWithTitle:image:target:action:menu:")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public UIBarButtonItem(string? title, UIKit.UIImage? image, Foundation.NSObject? target, ObjCRuntime.Selector? action, UIKit.UIMenu? menu);
[<Foundation.Export("initWithTitle:image:target:action:menu:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : string * UIKit.UIImage * Foundation.NSObject * ObjCRuntime.Selector * UIKit.UIMenu -> UIKit.UIBarButtonItem

Parameters

title
String
image
UIImage
target
NSObject
action
Selector
menu
UIMenu
Attributes

Applies to

UIBarButtonItem(UIBarButtonSystemItem, UIAction)

[Foundation.Export("initWithBarButtonSystemItem:primaryAction:")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public UIBarButtonItem(UIKit.UIBarButtonSystemItem systemItem, UIKit.UIAction? primaryAction);
[<Foundation.Export("initWithBarButtonSystemItem:primaryAction:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : UIKit.UIBarButtonSystemItem * UIKit.UIAction -> UIKit.UIBarButtonItem

Parameters

primaryAction
UIAction
Attributes

Applies to

UIBarButtonItem(UIAction, UIMenu)

[Foundation.Export("initWithPrimaryAction:menu:")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public UIBarButtonItem(UIKit.UIAction? primaryAction, UIKit.UIMenu? menu);
[<Foundation.Export("initWithPrimaryAction:menu:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : UIKit.UIAction * UIKit.UIMenu -> UIKit.UIBarButtonItem

Parameters

primaryAction
UIAction
menu
UIMenu
Attributes

Applies to

UIBarButtonItem(String, UIMenu)

[Foundation.Export("initWithTitle:menu:")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public UIBarButtonItem(string? title, UIKit.UIMenu? menu);
[<Foundation.Export("initWithTitle:menu:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : string * UIKit.UIMenu -> UIKit.UIBarButtonItem

Parameters

title
String
menu
UIMenu
Attributes

Applies to

UIBarButtonItem(UIView)

[Foundation.Export("initWithCustomView:")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public UIBarButtonItem(UIKit.UIView customView);
[<Foundation.Export("initWithCustomView:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : UIKit.UIView -> UIKit.UIBarButtonItem

Parameters

customView
UIView
Attributes

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(UIAction)

[Foundation.Export("initWithPrimaryAction:")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public UIBarButtonItem(UIKit.UIAction? primaryAction);
[<Foundation.Export("initWithPrimaryAction:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : UIKit.UIAction -> UIKit.UIBarButtonItem

Parameters

primaryAction
UIAction
Attributes

Applies to

UIBarButtonItem(NativeHandle)

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

[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
protected internal UIBarButtonItem(ObjCRuntime.NativeHandle handle);
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : ObjCRuntime.NativeHandle -> UIKit.UIBarButtonItem

Parameters

handle
NativeHandle

Pointer (handle) to the unmanaged object.

Attributes

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 GetNSObject(IntPtr) as it will prevent two instances of a managed object pointing to the same native object.

Applies to

UIBarButtonItem(NSObjectFlag)

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

[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
protected UIBarButtonItem(Foundation.NSObjectFlag t);
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
new UIKit.UIBarButtonItem : Foundation.NSObjectFlag -> UIKit.UIBarButtonItem

Parameters

t
NSObjectFlag

Unused sentinel value, pass NSObjectFlag.Empty.

Attributes

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 this constructor, 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 this constructor chain.

In general, if the developer's constructor invokes the corresponding base implementation, then it should also call 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 constructor merely allocates the object and registers the C# class with the Objective-C runtime if necessary.
// No actual initXxx method is invoked, that is done later in the constructor
//
// This is taken from the iOS SDK's source code for the UIView class:
//
[Export ("initWithFrame:")]
public UIView (CGRect 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.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
[ObjCRuntime.DesignatedInitializer]
public UIBarButtonItem(Foundation.NSCoder coder);
[<Foundation.Export("initWithCoder:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
[<ObjCRuntime.DesignatedInitializer>]
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.

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

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

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

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

Parameters

image
UIImage
landscapeImagePhone
UIImage
target
NSObject
action
Selector
Attributes

Applies to