IPhone DevelopmentIsUINavigationBarSetBackground ImageThe method is described in this article.IPhone Development, Sometimes we want to add a navigation barBackground ImageTo achieve a variety of navigation bar effects, other methods often fail to achieve the desired results, after online search and multiple experiments, determine the following best implementation scheme.
Add the following Category to UINavigatonBar:
- @implementation UINavigationBar (CustomImage)
- - (void)drawRect:(CGRect)rect {
- UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];
- [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- }
- @end
For example, in my project, add the following code:
- /* 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];
- }
The effects are as follows:
Summary:IPhone DevelopmentIsUINavigationBarSetBackground ImageThe content of this method has been introduced. I hope this article will help you!