MDCNavigationBar

@interface MDCNavigationBar : UIView <MDCElevatable, MDCElevationOverriding>

The MDCNavigationBar class is a view consisting of a leading and trailing button bar, title label, and an optional title view.

This view is not designed to have subviews added to it except via through its declared properties (e.g. titleView).

  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, copy, nullable) NSString *title
  • The title view layout differs from the traditional behavior of UINavigationBar.

    Due to MDCNavigationBar being able to expand vertically, the titleView’s height is updated to match any changes in the MDCNavigationBar’s height.

    You may wish to create a container view that is able to manage subview layout if your situation requires it.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIView *titleView;
  • The behavior that determines how to position the title view.

    By default this is MDCNavigationBarTitleViewLayoutBehaviorFill.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        MDCNavigationBarTitleViewLayoutBehavior titleViewLayoutBehavior;
  • The horizontal insets that the MDCNavigationBar uses for both the title and titleView. In right-to-left the titleInset.left will be used for the right side and the titleInset.right will be used for the left side.

    Defaults to UIEdgeInsets(0, 16, 0, 16).

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) UIEdgeInsets titleInsets;
  • The font applied to the title of navigation bar. Font size is enforced to 20. Both Default and null_resettable value is MDCTypography’s titleFont. Note that the font attribute of titleTextAttributes will take precedence over this property.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, null_resettable) UIFont *titleFont;
  • A behavioral flag that affects whether titleFont can be set to a font of any size or not.

    If enabled, titleFont can be set to a font of any size.

    If disabled, titleFont’s size will be adjusted to 20 regardless of the provided font size.

    We intend to enable this property by default in the future and to remote this flag entirely. Consider enabling this flag on your navigation bar instances.

    Default is NO.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL allowAnyTitleFontSize;
  • The title label’s text color.

    Default is nil (text draws black).

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *titleTextColor;
  • The rippleColor that is used for all buttons in trailing and leading button bars.

    If set to nil, button bar buttons use default ripple color.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *rippleColor;
  • By setting this property to @c YES, the Ripple component will be used instead of Ink to display visual feedback to the user.

    Note

    This property will eventually be enabled by default, deprecated, and then deleted as part of our migration to Ripple. Learn more at https://github.com/material-components/material-components-ios/tree/develop/components/Ink#migration-guide-ink-to-ripple

    Defaults to NO.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL enableRippleBehavior;
  • If true, all button titles will be converted to uppercase.

    Changing this property to NO will update the current title string for all buttons.

    Default is YES.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL uppercasesButtonTitles;
  • Sets the title font for the given state for all buttons.

    Declaration

    Objective-C

    - (void)setButtonsTitleFont:(nullable UIFont *)font
                       forState:(UIControlState)state;

    Parameters

    font

    The font that should be displayed on text buttons for the given state.

    state

    The state for which the font should be displayed.

  • Returns the font set for @c state that was set by setButtonsTitleFont:forState:.

    If no font has been set for a given state, the returned value will fall back to the value set for UIControlStateNormal.

    Declaration

    Objective-C

    - (nullable UIFont *)buttonsTitleFontForState:(UIControlState)state;

    Parameters

    state

    The state for which the font should be returned.

    Return Value

    The font associated with the given state.

  • Sets the title label color for the given state for all buttons.

    Declaration

    Objective-C

    - (void)setButtonsTitleColor:(nullable UIColor *)color
                        forState:(UIControlState)state;

    Parameters

    color

    The color that should be used on text buttons labels for the given state.

    state

    The state for which the color should be used.

  • The tint color applied to the bar items on the leading side of the BottomAppBar. If unset, then defaults to using this Navigation Bar’s @c tintColor.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable)
        UIColor *leadingBarItemsTintColor;
  • The tint color applied to the bar items on the trailing side of the BottomAppBar. If unset, then defaults to using this NavigationBar’s @c tintColor.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable)
        UIColor *trailingBarItemsTintColor;
  • Returns the color set for @c state that was set by setButtonsTitleColor:forState:.

    If no value has been set for a given state, the returned value will fall back to the value set for UIControlStateNormal.

    Declaration

    Objective-C

    - (nullable UIColor *)buttonsTitleColorForState:(UIControlState)state;

    Parameters

    state

    The state for which the color should be returned.

    Return Value

    The color associated with the given state.

  • The back button to be displayed, if any.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIBarButtonItem *backItem;
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic) BOOL hidesBackButton
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, copy, nullable) NSArray<UIBarButtonItem *> *leadingBarButtonItems
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, copy, nullable) NSArray<UIBarButtonItem *> *trailingBarButtonItems
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic) BOOL leadingItemsSupplementBackButton
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong, nullable) UIBarButtonItem *leadingBarButtonItem
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong, nullable) UIBarButtonItem *trailingBarButtonItem
  • Returns the rect of the leading item’s view within the given @c coordinateSpace.

    If the provided item is not contained in @c leadingBarButtonItems, then the behavior is undefined.

    Declaration

    Objective-C

    - (CGRect)rectForLeadingBarButtonItem:(nonnull UIBarButtonItem *)item
                        inCoordinateSpace:
                            (nonnull id<UICoordinateSpace>)coordinateSpace;

    Parameters

    item

    The item within @c leadingBarButtonItems whose rect should be computed.

    coordinateSpace

    The coordinate space the returned rect should be in relation to.

  • Returns the rect of the trailing item’s view within the given @c coordinateSpace.

    If the provided item is not contained in @c trailingBarButtonItems, then the behavior is undefined.

    Declaration

    Objective-C

    - (CGRect)rectForTrailingBarButtonItem:(nonnull UIBarButtonItem *)item
                         inCoordinateSpace:
                             (nonnull id<UICoordinateSpace>)coordinateSpace;

    Parameters

    item

    The item within @c trailingBarButtonItems whose rect should be computed.

    coordinateSpace

    The coordinate space the returned rect should be in relation to.

  • The horizontal text alignment of the navigation bar title. Defaults to MDCNavigationBarTitleAlignmentLeading.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        MDCNavigationBarTitleAlignment titleAlignment;
  • A block that is invoked when the NavigationBar receives a call to @c traitCollectionDidChange:. The block is called after the call to the superclass.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) void (^)
        (MDCNavigationBar *_Nonnull, UITraitCollection *_Nullable)
            traitCollectionDidChangeBlock;
  • Begin observing changes to the provided navigation item.

    Only one navigation item instance can be observed at a time. Observing a second navigation item will stop observation of the first navigation item.

    Once execution returns from this method the receiver’s state will match that of the newly-observed navigation item.

    The observed navigation item is strongly held.

    Declaration

    Objective-C

    - (void)observeNavigationItem:(nonnull UINavigationItem *)navigationItem;
  • Stop observing changes to the previously-observed navigation item.

    Does nothing if no navigation item is being observed.

    Declaration

    Objective-C

    - (void)unobserveNavigationItem;
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, copy, nullable) NSArray<UIBarButtonItem *> *leftBarButtonItems
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, copy, nullable) NSArray<UIBarButtonItem *> *rightBarButtonItems
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong, nullable) UIBarButtonItem *leftBarButtonItem
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong, nullable) UIBarButtonItem *rightBarButtonItem
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic) BOOL leftItemsSupplementBackButton
  • Display attributes for the titleView’s title text.

    Font attribute will take precedence over titleFont property. Setting this property will render an NSAttributedString with the assigned attributes across the entire text.

    Note: this property will be deprecated in future, please use titleFont and titleTextColor instead.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable)
        NSDictionary<NSAttributedStringKey, id> *titleTextAttributes;
  • The text alignment of the navigation bar title. Defaults to NSTextAlignmentLeft.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) NSTextAlignment textAlignment;