• Stars
    star
    916
  • Rank 48,142 (Top 1.0 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

CRMotionView

A custom photo viewer that implements device motion scrolling, inspired by Facebook Paper.
Objective-C
760
star
2

Doppio

An open source iOS app to find the nearest Starbucks store using NSURLSession, AFNetworking 2.0, Mantle and Starbucks private API.
Objective-C
555
star
3

CRPixellatedView

Custom UIView subclass with a pixellated animation inspired by Facebook's Slingshot app.
Objective-C
377
star
4

ANPR

License plate recognition for iOS using OpenCV & Tesseract OCR Engine
C++
252
star
5

CRMultiRowSelect

Custom UITableViewCell for iOS that supports multiple row selection
Objective-C
171
star
6

HeartBeats

Source code for iOS app to draw heart beats by reading color changes using the device flash led and CoreGraphics.
Objective-C
166
star
7

CRMediaPickerController

An easy-to-use UIImagePickerController replacement for picking Images and Videos.
Objective-C
166
star
8

CRGradientLabel

Custom UILabel subclass with gradient coloured background, written in Swift.
Swift
50
star
9

repuve-api

Python
11
star
10

df-gtfs

Script para importar dataset de "df_gtfs" a PostgreSQL
11
star
11

Ecobici

Ecobici+ iOS app. Disponibilidad inteligente de Ecobici, ciclovias y rutas seguras. #hackdf
Objective-C
10
star
12

API-SCT

API para consumir datos de rutas a traves de SCT
Ruby
8
star
13

XReset

Xcode Plugin to Reset iOS Simulators Content and Settings.
Objective-C
7
star
14

congreso

iOS app for #app115 challenge which Mexican House of Representatives announced that they were planning to pay $9.3 million to have an app developed. This an open source version and was presented at Mexican Congress.
Objective-C
7
star
15

FaceMemesCV

Live face detection & memes with OpenCV
C++
5
star
16

Toggle

Google Chrome extension to toggle between .h and .m source files on GitHub.
JavaScript
4
star
17

memeAR

iPhone app that detects real time faces and add memes
Objective-C
4
star
18

meds

Meds application for Android
Java
3
star
19

TextureViewDemo

Android TextureView Demo like the new Youtube app.
Java
3
star
20

chroMVC

PHP MVC framework based on Sinatra
JavaScript
2
star
21

cpmx4-chat

CPMX4 Node.js Chat
CSS
1
star
22

Programming-challenges

Programming challenges that solve in my free time from the book: The programming contest training manual
Java
1
star