CRGradientNavigationBar icon indicating copy to clipboard operation
CRGradientNavigationBar copied to clipboard

Navigaton Bar for Single Controller

Open prnk28 opened this issue 11 years ago • 3 comments

How would you change the view controller for only one View Controller rather than the whole application

prnk28 avatar Oct 30 '13 18:10 prnk28

if you want to change the colour dynamically for only one View Controller you can use:

[[CRGradientNavigationBar appearance] setBarTintColors:colors];

This also works with an UINavigationBar IBOutlet (w/o an UINavigationController): Place a navigation bar onto your view in IB. In IB set the navigation bar class to CRGradientNavigationBar (Same steps if you are using Storyboards). http://stackoverflow.com/questions/19174542/initwithnavigationbarclass-for-uinavigationcontroller-in-a-storyboard-applicatio

Also, if you choose to use a Navigation Controller (as the example). Hide the bar on the first screen, show the bar on the second screen or something like this using the viewWillAppear: and viewWilDisappear: methods of your UIViewController as a good place to control the visibility of the navigation controller's bar.

Hope it helps.

christianroman avatar Oct 31 '13 16:10 christianroman

@chroman, with my experience, this is not 100% dynamic. If I call [[CRGradientNavigationBar appearance] setBarTintColors:colors]; after I call [[CRGradientNavigationBar appearance] setBarTintGradientColors:colors]; it stays on the gradient and does not go to a flat color.

Any way to get this to work?

levibostian avatar Jan 13 '16 16:01 levibostian

I ended up solving the issue that I needed. After checking out this pull request, I pulled down the master branch of the pull request and ran the demo and learned:

UIColor *firstColor = [UIColor colorWithRed:255.0f/255.0f green:42.0f/255.0f blue:104.0f/255.0f alpha:1.0f];
UIColor *secondColor = [UIColor colorWithRed:255.0f/255.0f green:90.0f/255.0f blue:58.0f/255.0f alpha:1.0f];
NSArray *colors = [NSArray arrayWithObjects:firstColor, secondColor, nil];

CRGradientNavigationBar *bar = (CRGradientNavigationBar *)self.navigationController.navigationBar;
    [bar setBarTintGradientColors:colors];

instead of:

[[CRGradientNavigationBar appearance] setBarTintColors:colors];

Thank you

levibostian avatar Jan 20 '16 23:01 levibostian

Thanks for the help guys - I was 16 when I asked this time to close this issue 🤣

prnk28 avatar Feb 02 '24 10:02 prnk28