Tag Archives: objective c

Custom UINavigationBar

Since I’ve moved over to just doing mobile dev (iPhone/iOS specifically), I thought I’d start occasionally posting some Objective-C code snippets. Coming from a PHP background its been a bit of a learning curve.

This is a simple Category to create a custom UINavigationBar inorder to apply it to the entire app. I only needed to set a background image so its really simple.

 

UINavigationBarSilver.h

#import 
 
@interface UINavigationBar (UINavigationBarSilver)
 
@end
UINavigationBarSilver.m
#import "UINavigationBarSilver.h"
 
@implementation UINavigationBar (UINavigationBarSilver)
 
- (void)drawRect:(CGRect)rect {
	UIColor *color = [UIColor clearColor];
	UIImage *img	= [UIImage imageNamed: @"top_nav_bg.png"];
	[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
	self.tintColor = color;
}
 
@end