Navigation bar customization

A navigation bar appears at the top of an app screen, below the status bar. Navigation bar contains the navigation buttons of a navigation controller, which is a stack of view controllers which can be pushed and popped.

Let’s do something with Navigation bar

  1. Hide navigation bar

    [self.navigationController setNavigationBarHidden:YES animated:YES];
  2. Change navigation bar color

    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
  3. Change navigation tint color

    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  4. Change navigation bar Title

    self.navigationItem.title = @"This is title text";
  5. Change navigation bar title color

    [self.navigationController.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
    [UIFont fontWithName:@"HelveticaNeue-Light" size:18.0], NSFontAttributeName, nil]];
  6. Hide back text from back button

    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
  7. Hide back button

    [self.navigationItem setHidesBackButton:YES animated:YES];
  8. Add left button with Image

    UIImage *image = [[UIImage imageNamed:@"menu.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(menuBtnClicked:)];
    self.navigationItem.leftBarButtonItem = button;
  9. Add right button

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addBtnAction:)];
    self.navigationItem.rightBarButtonItem = addButton;

That’s It. If you like this post, Please comment below and subscribe this blog.

Leave your comments