// 初始化一个navbar
_mNavigationBar = [[UINavigationBar alloc] initWithFrame:self.bounds];
//导航条背景
UIColor *color = [UIColor colorWithRed:46.0f/255.0f green:87.0f/255.0f blue:29.0f/255.0f alpha:1.0f];
_mNavigationBar.tintColor = color;[_mNavigationBar setBarStyle:UIBarStyleBlackTranslucent];
[self addSubview:_mNavigationBar];
//创建一个导航栏集合
UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:nil];
[navigationItem setTitle:@"发行基金物流商业银行软件"];
//把导航栏集合添加入导航栏中,设置动画关闭
[_mNavigationBar pushNavigationItem:navigationItem animated:NO];
// 创建一个左边按钮
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"设置"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(buttonAction:)];
[leftButton setTag:12];
//创建一个右边按钮
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"扫描枪"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(buttonAction:)];
[rightButton setTag:11];
//把左右两个按钮添加入导航栏集合中
[_mNavigationBar.topItem setLeftBarButtonItem:leftButton];
[_mNavigationBar.topItem setRightBarButtonItem:rightButton];
如果想要自定义导航栏背景的话,
ios5只需要一句话
[_mNavigationBar setBackgroundImage:[UIImage imageNamed:@"btn5.jpg"] forBarMetrics:UIBarMetricsDefault];