Skip to content

Instantly share code, notes, and snippets.

Created January 5, 2015 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/852b61188f29eee2997e to your computer and use it in GitHub Desktop.
Save anonymous/852b61188f29eee2997e to your computer and use it in GitHub Desktop.
diff -r 0bf742d304c6 -r 3f339c9d340d Classes/Helpers/QNavigationController.m
--- a/Classes/Helpers/QNavigationController.m Mon Jan 05 01:14:44 2015 +0200
+++ b/Classes/Helpers/QNavigationController.m Mon Jan 05 01:28:48 2015 +0200
@@ -7,6 +7,7 @@
//
#import "QNavigationController.h"
+#import "QBar.h"
@implementation QNavigationController
@@ -14,6 +15,7 @@
{
[super awakeFromNib];
self.navigationBar.barStyle = UIBarStyleBlack;
+ [self setGradientToNavigationBar];
self.navigationBar.translucent = NO;
if (IOS7) {
self.navigationBar.tintColor = [UIColor whiteColor];
@@ -26,6 +28,7 @@
self = [super initWithRootViewController:rootViewController];
if (self) {
self.navigationBar.barStyle = UIBarStyleBlack;
+ [self setGradientToNavigationBar];
self.navigationBar.translucent = NO;
if (IOS7) {
self.navigationBar.tintColor = [UIColor whiteColor];
@@ -35,4 +38,31 @@
return self;
}
+- (void) setGradientToNavigationBar {
+ self.navigationBar.barTintColor = topBlueGradientColor;
+
+ CGRect bounds = self.navigationBar.bounds;
+ if(IOS7) {
+ bounds.size.height += 20;
+ }
+
+ CALayer * bgGradientLayer = [self gradientBGLayerForBounds:bounds];
+ UIGraphicsBeginImageContext(bounds.size);
+ [bgGradientLayer renderInContext:UIGraphicsGetCurrentContext()];
+ UIImage * bgAsImage = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ if (bgAsImage != nil)
+ {
+ [[UINavigationBar appearance] setBackgroundImage:bgAsImage forBarMetrics:UIBarMetricsDefault];
+ }
+}
+
+- (CALayer *)gradientBGLayerForBounds:(CGRect)bounds
+{
+ CAGradientLayer * gradientBG = [CAGradientLayer layer];
+ gradientBG.frame = bounds;
+ gradientBG.colors = @[ (id)[topBlueGradientColor CGColor], (id)[bottomBlueGradientColor CGColor] ];
+ return gradientBG;
+}
+
@end
diff -r 0bf742d304c6 -r 3f339c9d340d Classes/Views/QBar.h
--- a/Classes/Views/QBar.h Mon Jan 05 01:14:44 2015 +0200
+++ b/Classes/Views/QBar.h Mon Jan 05 01:28:48 2015 +0200
@@ -13,6 +13,9 @@
#import "QBarButtonView.h"
#import "QMutables.h"
+#define topBlueGradientColor [UIColor colorWithRed:27/255.0 green:167/255.0 blue:254/255.0 alpha:1.0]
+#define bottomBlueGradientColor [UIColor colorWithRed:27/255.0 green:103/255.0 blue:240/255.0 alpha:1.0]
+
typedef enum _QBarStyle{
BarStyleBlack = 1,
BarStyleBlue = 2,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment