---
title: "如何为UINavigationBar设置背景图片"
author: "niCe"
date: "2010-12-31T10:48:59Z"
tags: []
categories: ["移动开发"]
slug: "uinavigationbar"
draft: false
lastmod: "2010-12-31T10:48:59Z"
id: 856607
url: "https://nice.iteye.com/blog/856607"
---

```
/////////////////////////////////////////////////////////
/* input: The image and a tag to later identify the view */
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
	UIImage *image = [UIImage imageNamed: @"title_bg.png"];
	[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
/////////////////////////////////////////////////////////
@implementation FriendsPageViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {	
	self.navigationBar.tintColor = [UIColor purpleColor];
	
	[self initWithRootViewController:[[RegPageViewController alloc] init]];
    [super viewDidLoad];
}
......
```

 

实现的效果如下图:

 

![](http://p.blog.csdn.net/images/p_blog_csdn_net/wave_1102/EntryImages/20091104/navBackImage.png)