124th Day As An iOS Developer - Category For UINavigationController

March 4, 2016 - 124th Day As An iOS Developer

FRIDAY - Ok, I will post this post as fast as I can, because I got many things to do. I'm typing this today, March 7 8:30 AM - Monday. My shift doesn't start yet but I'm so ready to to programming. I gotta share something to this post real quick : A category for UINavigationController. Basically, this category, what this does is it lets your Navigation Controller call a method to either hide or present your Navigation Bar and make it transparent.

So here's the code, by the way, I got this from SO. But I just made it a category - wait, I'm not sure if the one who made this code shared it as a category, but anyway, here it is:


#import <UIKit/UIKit.h> 
@interface UINavigationController (TransparentNavigationController)
- (void)presentTransparentNavigationBar;
- (void)hideTransparentNavigationBar;


#import "UINavigationController+TransparentNavigationController.h"

@implementation UINavigationController (TransparentNavigationController)

- (void)presentTransparentNavigationBar
    [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationBar setTranslucent:YES];
    [self.navigationBar setShadowImage:[UIImage new]];
    [self setNavigationBarHidden:NO animated:YES];

- (void)hideTransparentNavigationBar
    [self setNavigationBarHidden:YES animated:NO];
    [self.navigationBar setBackgroundImage:[[UINavigationBar appearance] backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
    [self.navigationBar setTranslucent:[[UINavigationBar appearance] isTranslucent]];
    [self.navigationBar setShadowImage:[[UINavigationBar appearance] shadowImage]];


So there you go folks, oh, by the way, I tried working last Sunday - yesterday, I mean, I learned masking images, I just finished setting up my Map Screen for the App.


Post a Comment