Skip to content

Instantly share code, notes, and snippets.

@ahmetardal
Created February 11, 2011 06:09
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 ahmetardal/821991 to your computer and use it in GitHub Desktop.
Save ahmetardal/821991 to your computer and use it in GitHub Desktop.
//
// UINavigationBar+CustomBackground.h
// CustomizingNavigationBarBackground
//
// Created by Ahmet Ardal on 2/10/11.
// Copyright 2011 LiveGO. All rights reserved.
//
#import <Foundation/Foundation.h>
#define kNavigationBarCustomTintColor [UIColor colorWithRed:0.093 green:0.653 blue:0.828 alpha:1.0]
@interface UINavigationBar(CustomBackground)
- (void) applyCustomTintColor;
@end
//
// UINavigationBar+CustomBackground.m
// CustomizingNavigationBarBackground
//
// Created by Ahmet Ardal on 2/10/11.
// Copyright 2011 LiveGO. All rights reserved.
//
#import "UINavigationBar+CustomBackground.h"
@implementation UINavigationBar(CustomBackground)
+ (UIImage *) bgImagePortrait
{
static UIImage *image = nil;
if (image == nil) {
image = [[UIImage imageNamed:@"navbar_bg_portrait"] retain];
}
return image;
}
+ (UIImage *) bgImageLandscape
{
static UIImage *image = nil;
if (image == nil) {
image = [[UIImage imageNamed:@"navbar_bg_landscape"] retain];
}
return image;
}
- (void) drawLayer:(CALayer *)layer inContext:(CGContextRef)context
{
if ([self isMemberOfClass:[UINavigationBar class]] == NO) {
return;
}
UIImage *image = (self.frame.size.width > 320) ?
[UINavigationBar bgImageLandscape] : [UINavigationBar bgImagePortrait];
CGContextClip(context);
CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), image.CGImage);
}
- (void) applyCustomTintColor
{
[self setTintColor:kNavigationBarCustomTintColor];
}
@end
//
// UINavigationBar+CustomBackground.h
// CustomizingNavigationBarBackground
//
// Created by Ahmet Ardal on 2/10/11.
// Copyright 2011 SpinningSphere Labs. All rights reserved.
//
#import <Foundation/Foundation.h>
#define kNavigationBarCustomTintColor [UIColor colorWithRed:0.093 green:0.653 blue:0.828 alpha:1.0]
@interface UINavigationBar(CustomBackground)
- (void) applyCustomTintColor;
@end
//
// UINavigationBar+CustomBackground.m
// CustomizingNavigationBarBackground
//
// Created by Ahmet Ardal on 2/10/11.
// Copyright 2011 SpinningSphere Labs. All rights reserved.
//
#import "UINavigationBar+CustomBackground.h"
@implementation UINavigationBar(CustomBackground)
+ (UIImage *) bgImagePortrait
{
static UIImage *image = nil;
if (image == nil) {
image = [[UIImage imageNamed:@"navbar_bg_portrait"] retain];
}
return image;
}
+ (UIImage *) bgImageLandscape
{
static UIImage *image = nil;
if (image == nil) {
image = [[UIImage imageNamed:@"navbar_bg_landscape"] retain];
}
return image;
}
- (void) drawLayer:(CALayer *)layer inContext:(CGContextRef)context
{
if ([self isMemberOfClass:[UINavigationBar class]] == NO) {
return;
}
UIImage *image = (self.frame.size.width > 320) ?
[UINavigationBar bgImageLandscape] : [UINavigationBar bgImagePortrait];
CGContextClip(context);
CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), image.CGImage);
}
- (void) applyCustomTintColor
{
[self setTintColor:kNavigationBarCustomTintColor];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment