CustomNavController.h
// Created by suruiqiang on 8/3/10.// Copyright 2010 __MyCompanyName__. All rights reserved.//#pragma once#import <UIKit/UIKit.h>@interface UINavigationBar (UINavigationBarCategory) UIImageView *bg;-(UINavigationBar*)setBackgroundImage:(UIImage*)image;- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;@end
CustomNavController.m
#import "CustomerNavBarController.h"@implementation UINavigationBar (UINavigationBarCategory)-(UINavigationBar*)setBackgroundImage:(UIImage*)image{UINavigationBar *NavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; if(image == nil) return NavBar; bg = [[UIImageView alloc]initWithImage:image]; bg.frame = CGRectMake(0.f, 0.f, self.frame.size.width, self.frame.size.height); [NavBar addSubview:bg]; [NavBar sendSubviewToBack:bg]; [bg release];return NavBar;}- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index{ [super insertSubview:view atIndex:index]; [self sendSubviewToBack:bg];}@end
在需要調用的地方添加如下代碼:
- (void)viewDidLoad { [super viewDidLoad]; [[self.navigationController navigationBar] setBackgroundImage:[UIImage imageNamed:@"NavigationBarBackground.png"]];//在下面添加你自己的功能代碼***********}