Git Product home page Git Product logo

crgradientnavigationbar's Introduction

CRGradientNavigationBar

Custom UINavigationBar subclass which allows gradient coloured navigation bar on iOS 6/7.

CRGradientNavigationBar-main

Usage

  1. Add the dependency to your Podfile:
platform :ios
pod 'CRGradientNavigationBar'
...
  1. Run pod install to install the dependencies.

  2. Import the header file wherever you want to use the gradient colored navigation bar:

#import "CRGradientNavigationBar.h"
  1. Use with UINavigationController's initWithNavigationBarClass:toolbarClass: method:
UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[CRGradientNavigationBar class] toolbarClass:nil];
  1. Use an NSArray to set the gradient colors (You can set unlimited colors):
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];
  1. Set the gradient colors via NSArray using UIAppearance setBarTintGradientColors: method:
[[CRGradientNavigationBar appearance] setBarTintGradientColors:colors];
  1. Remember to set (YES) or not (NO) to translucent value using setTranslucent: method:
[[navigationController navigationBar] setTranslucent:NO];

You can change the transparency default value (0.5f), just change this line in the CRGradientNavigationBar.m file:

static CGFloat const kDefaultOpacity = 0.5f;

Full example:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[CRGradientNavigationBar class] toolbarClass:nil];
    
    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];
    // or NSArray *colors = [NSArray arrayWithObjects:(id)UIColorFromRGB(0xf16149).CGColor, (id)UIColorFromRGB(0xf14959).CGColor, nil];
    
    [[CRGradientNavigationBar appearance] setBarTintGradientColors:colors];
    [[navigationController navigationBar] setTranslucent:NO]; // Remember, the default value is YES.
    
    DemoViewController *viewController = [[DemoViewController alloc] init];
    [navigationController setViewControllers:@[viewController]];
    
    [self.window setRootViewController:navigationController];
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

Example gradient combinations

  • Translucent = NO

CRGradientNavigationBar-sample1

CRGradientNavigationBar-sample2

  • Translucent = YES

CRGradientNavigationBar-sample3

  • Example using three different colors and translucent` value to NO

CRGradientNavigationBar-combination

  • If you need just one color use UIAppearance setBarTintColor: method:
[[CRGradientNavigationBar appearance] setBarTintColor:UIColorFromRGB(0xEE695D)];

CRGradientNavigationBar-simple

Translucent demo 1:

CRGradientNavigationBar-demo1

Translucent demo 2:

CRGradientNavigationBar-demo1

Requirements

  • iOS 6.0 or higher
  • ARC

License

CRGradientNavigationBar is released under the MIT license. See LICENSE.

Contact me

Christian Roman

Website: http://chroman.me

Contact: [email protected]

Twitter: http://twitter.com/chroman

crgradientnavigationbar's People

Contributors

christianroman avatar nebulafox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crgradientnavigationbar's Issues

Double Navigation Bars

My app is a Tab Bar Controller app, in which each tab is a NavigationController. I have my code set as:

`UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[CRGradientNavigationBar class] toolbarClass:nil];

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];
// or NSArray *colors = [NSArray arrayWithObjects:(id)UIColorFromRGB(0xf16149).CGColor, (id)UIColorFromRGB(0xf14959).CGColor, nil];

[[CRGradientNavigationBar appearance] setBarTintGradientColors:colors];
[[navigationController navigationBar] setTranslucent:NO]; // Remember, the default value is YES.

[navigationController setViewControllers:@[tabBarController]];

[self.window setRootViewController:navigationController];`

However, I am getting double navigation bars, with title and uibarbuttonitems being added to the 2nd, and not the gradient one. Any suggestions?

ios simulator screen shot jan 15 2015 9 56 47 am

Gradient not showing โ€“ only the second color

I set the class CRGradientNavigationBar to the NavigationBar in my Storyboard.

Then in my custom UINavigationController class I do this in the viewDidLoad:

UIColor *firstColor = [UIColor colorWithRed:0/255.0f green:0/255.0f blue:255/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 appearance] setBarTintGradientColors:colors];
[self.navigationBar setTranslucent:NO];

The bar changes it's color, but only to the second one provided.

Thanks in advance.

Totally different if set translucent yes

Downloaded the demo, on iOS 7, run it after just only set translucent = YES, it looks totally different from NO.

How to handle the actual effect of color gradient with translucent, which are like your screenshots.

img_1352

Horizontal gradients?

This library looks like a lifesaver! I need to do something exactly like this (with a translucent gradient), however, I need the gradient to be horizontal, rather than vertical. Is this supported? Or how could I extend this library to support this feature?

EKEventEditViewController don't work with Gradient

It is possible using gradient in this case?

EKEventEditViewController *controller2 = [[EKEventEditViewController alloc] initWithNavigationBarClass:[CRGradientNavigationBar class] toolbarClass:nil];

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 appearance] setBarTintGradientColors:colors];
[[controller2 navigationBar] setTranslucent:NO];

Storyboards?

I'm using storyboards so I don't use the App Delegate class to initialize my views. How would I implement the CRGradientNavBar then? Is it not possible?

[[UINavigationBar appearance] setTintColor:[~gradient~]]

Modal view

I have CRGradientNavigationBar set to translucnet=NO, and it works great.

But when I call a modal view which also has translucent=NO the color gets darker.

How can I have modal view get the same color?

Navigation bar
ios simulator screen shot 2014 1 2 12 59 28

Navigation bar in modal view
ios simulator screen shot 2014 1 2 12 59 31

Gradient colors showing as much darker than specified colors

Hey croman,

Your navigation bar works great, but the colors that I include in the array show up much darker than they should. When I set both gradient colors to white (ffffff) then the nav bar is a solid gray.

Thanks for your help! I'm using storyboards.

Allow other directions

Would be great to be able to have the gradient from left to right for instance.
The CRGradientNavigationBar class could have a property named gradientDirection which would be an enum CRGradientDirection.

Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.