UINavigationBar设置背景图片

头文件:

 

#import <Foundation/Foundation.h>

@interface UINavigationBar (BackgroundImage) 

UIImageView *backgroundView;
- (void)setBackgroundImage:(UIImage *)image;

@end

 

实现文件:

 

#import "UINavigationBar.h"

@implementation UINavigationBar (BackgroundImage) 

- (void)setBackgroundImage:(UIImage*)image
{
	if(image == nil)
	{
		[backgroundView removeFromSuperview];
	}
	else
	{
		backgroundView = [[UIImageView alloc] initWithImage:image];
		backgroundView.frame = CGRectMake(0.f, 0.f, self.frame.size.width, self.frame.size.height);
		backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
		[self addSubview:backgroundView];
		[self sendSubviewToBack:backgroundView];
		[backgroundView release];
	}
}

@end

 

你可能感兴趣的:(ios,iPhone,背景图片,UINavigationBar)