본문 바로가기

iOS

Custom NavigationBar 구현하기

iOS 5부터 navigationBar의 background를 넣는걸 지원해줘서 5이전과 이후의 코드가 다르다.
둘다 넣어주면 됨

iOS 5이전
AppDelegate.m

@implementation UINavigationBar(Custom) -(void)drawRect:(CGRect)rect{
 
UIImage *headerImage = [UIImage imageNamed:@"headbg.png"]; [headerImage drawInRect:rect]; } @end



iOS 5 이후
AppDelegate.m의 didFinishLaunchingWithOptins

if([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0){ UIImage *headerImage = [UIImage imageNamed:@"headbg.png"]; [[UINavigationBar appearance] setBackgroundImage:headerImage forBarMetrics:UIBarMetricsDefault]; }