material-components_materia.../components/AppBar/docs/typical-use-navigation-controller.md
featherless 4f181203ad
[AppBar] Complete pass at documentation modernization. (#4708)
This is a complete overhaul of the App Bar documentation, fully reflecting the most modern set of APIs that we encourage and expect clients to adopt.

As part of this work, I've also written up the documentation for the various behavioral flags.

Preview the App Bar docs: 007a738fa5/components/AppBar/README.md

Preview the Flexible Header docs: 007a738fa5/components/FlexibleHeader/README.md

Closes https://github.com/material-components/material-components-ios/issues/4653
2018-08-08 09:52:12 -04:00

1.8 KiB

Typical use: View controller containment, as a navigation controller

The easiest integration path for using the app bar is through the MDCAppBarNavigationController. This API is a subclass of UINavigationController that automatically adds an MDCAppBarViewController instance to each view controller that is pushed onto it, unless an app bar or flexible header already exists.

When using the MDCAppBarNavigationController you will, at a minimum, need to configure the added app bar's background color using the delegate.

Example

Swift

let navigationController = MDCAppBarNavigationController()
navigationController.pushViewController(<#T##viewController: UIViewController##UIViewController#>, animated: <#T##Bool#>)

// MARK: MDCAppBarNavigationControllerDelegate

func appBarNavigationController(_ navigationController: MDCAppBarNavigationController,
                                willAdd appBarViewController: MDCAppBarViewController,
                                asChildOf viewController: UIViewController) {
  appBarViewController.headerView.backgroundColor = <#(UIColor)#>
}

Objective-C

MDCAppBarNavigationController *navigationController =
    [[MDCAppBarNavigationController alloc] init];
[navigationController pushViewController:<#(nonnull UIViewController *)#> animated:<#(BOOL)#>];

#pragma mark - MDCAppBarNavigationControllerDelegate

- (void)appBarNavigationController:(MDCAppBarNavigationController *)navigationController
       willAddAppBarViewController:(MDCAppBarViewController *)appBarViewController
           asChildOfViewController:(UIViewController *)viewController {
  appBarViewController.headerView.backgroundColor = <#(nonnull UIColor *)#>;
}