iOS Guides | Samples

MonoTouch.UIKit.UINavigationBar Class

A UIView that displays the standard hierarchical navigation metaphor for iOS.

See Also: UINavigationBar

Syntax

[MonoTouch.Foundation.Register("UINavigationBar", true)]
public class UINavigationBar : UIView, IUIBarPositioning, IDisposable

See Also

Remarks

The MonoTouch API supports two styles of event notification: the Objective-C style that uses a delegate class or the C# style using event notifications.

The C# style allows the user to add or remove event handlers at runtime by assigning to the events of properties of this class. Event handlers can be anyone of a method, an anonymous methods or a lambda expression. Using the C# style events or properties will override any manual settings to the Objective-C Delegate or WeakDelegate settings.

The Objective-C style requires the user to create a new class derived from UINavigationBarDelegate class and assign it to the UIKit.Delegate property. Alternatively, for low-level control, by creating a class derived from NSObject which has every entry point properly decorated with an [Export] attribute. The instance of this object can then be assigned to the UINavigationBar.WeakDelegate property.

Structure

The UINavigationBar maintains a stack of UINavigationItems. The UINavigationBar displays the UINavigationBar.TopItemUINavigationItem. You can push and pop UINavigationItems using UINavigationBar.PushNavigationItem and UINavigationBar.PopNavigationItemAnimated.

The UINavigationBar is most commonly seen in conjunction with a UINavigationController, which manages the UINavigationBar and pushes and pops the necessary UINavigationItems.

Each UINavigationItem defines left, center, and right subviews. The left and right subviews are expected to be of type UIBarButtonItem, while the center subview by default displays the value of the UINavigationItem.Title property. The center view can be further customized by assigning to the UINavigationItem.TitleView property.

When used with a UINavigationController, the current UIViewController's UIViewController.NavigationItem property is used to manipulate the UINavigationBar, as shown in the following example.

C# Example

          public class MyViewController : UIViewController
          {
             public override void ViewDidLoad ()
             {
                base.ViewDidLoad ();
          
                this.NavigationItem.Title = "NavigationItem.Title";
                this.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, OnAction);
                //...etc....

Application developers who wish to customize the behavior of the UINavigationController's uniquely-styled '"Back" button when using a UINavigationController can use the following technique:

C# Example

          public class MyViewController : UIViewController
          {
             public override void ViewWillDisappear(bool animated)
             {
                base.ViewWillDisappear(animated);
                //If `this` not in stack, we've been popped via "Back" button
                if(NavigationController.ViewControllers.Contains(this) == false)
                {
                   Console.WriteLine("Custom behavior");
                }
             }
          }

Related content

Requirements

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

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

See Also: UIView

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.
Initializes the UINavigationBar with the specified frame.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

[read-only]
static
AppearanceUINavigationBar+UINavigationBarAppearance. Strongly-typed property that returns the UIAppearance class for this class.
BackIndicatorImageUIImage. The image shown beside the back button.
BackIndicatorTransitionMaskImageUIImage. The image used as a mask during push and pop transitions.
[read-only]
BackItemUINavigationItem. The UINavigationItem that is immediately below the top of the navigation stack.
[read-only]
BarPositionUIBarPosition. Delegate for the navigation bar.
BarStyleUIBarStyle. The visual style of the navigation bar.
BarTintColorUIColor. The tint color for the bar's background.
[read-only]
override
ClassHandleIntPtr. The handle for this class.
DelegateUINavigationBarDelegate. An instance of the MonoTouch.UIKit.UINavigationBarDelegate model class which acts as the class delegate.
ItemsUINavigationItem[]. The array of UINavigatorItems managed by the bar.
ShadowImageUIImage. Specifies a custom shadow image.
TitleTextAttributesUIStringAttributes. Display attributes that are set for the bar’s title text.
[read-only]
TopItemUINavigationItem. The UINavigationItem at the top of the stack being managed.
TranslucentBoolean. Whether the bar is translucent or not.
WeakDelegateNSObject. An object that can respond to the delegate protocol for this type

Public Methods

static
AppearanceWhenContainedIn(params Type[]) : UINavigationBar+UINavigationBarAppearance
Returns a strongly typed UIAppearance for instances of this class when the view is hosted in the specified hierarchy.
static
GetAppearance(UITraitCollection) : UINavigationBar+UINavigationBarAppearance
Returns an appearance proxy for the specified traits.
static
GetAppearance(UITraitCollection, params Type[]) : UINavigationBar+UINavigationBarAppearance
Returns an appearance proxy for the specified traits.
static
GetAppearance<T>() : UINavigationBar+UINavigationBarAppearance
Obtains the appearance proxy UINavigationBarAppearance for the subclass of UINavigationBar.
static
GetAppearance<T>(UITraitCollection) : UINavigationBar+UINavigationBarAppearance
Obtains the appearance proxy UINavigationBarAppearance for the subclass of UINavigationBar.
static
GetAppearance<T>(UITraitCollection, params Type[]) : UINavigationBar+UINavigationBarAppearance
Obtains the appearance proxy UINavigationBarAppearance for the subclass of UINavigationBar that has the specified trait collection when the view is hosted in the specified hierarchy.
GetBackgroundImage(UIBarMetrics) : UIImage
The background used when the UINavigationBar has the specified forBarMetrics.
GetBackgroundImage(UIBarPosition, UIBarMetrics) : UIImage
The background image used when the bar is in the specified barPosition and has the metrics specified by barMetrics.
GetTitleTextAttributes() : UITextAttributes
The text attributes used by the title.
GetTitleVerticalPositionAdjustment(UIBarMetrics) : Single
Gets the vertical adjustment for the specified barMetrics.
PopNavigationItemAnimated(Boolean) : UINavigationItem
Pops the topmost UINavigationItem, optionally animating the change.
PushNavigationItem(UINavigationItem, Boolean)
Pushes the item onto the navigation stack, optionally animating the change.
SetBackgroundImage(UIImage, UIBarMetrics)
Changes the background image for the barMetrics.
SetBackgroundImage(UIImage, UIBarPosition, UIBarMetrics)
Sets the background image for the barPosition and barMetrics.
SetItems(UINavigationItem[], Boolean)
Replaces the current set of navigation items with items, optionally animating the change of the top item.
SetTitleTextAttributes(UITextAttributes)
Specifies the attributes applied to the UINavigationItem.Title.
SetTitleVerticalPositionAdjustment(Single, UIBarMetrics)
Vertically shifts the location of the title in the navigation bar.

Protected Methods

override
Dispose(Boolean)
Releases the resources used by the UINavigationBar object.