iphone 导航栏背景
2013-12-20 13:00
211 查看
//CustomNavigationBar.h
@interface UINavigationBar (UINavigationBarCategory)
UIImageView *backgroundView;
- (void)setBackgroundImage:(UIImage*)image;
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
@end
//CustomNavigationBar.m
@implementation UINavigationBar (UINavigationBarCategory)
-(void)setBackgroundImage:(UIImage*)image
{
if(image == nil)
{
[backgroundView removeFromSuperview];
}
else
{
backgroundView = [[UIImageView alloc] initWithImage:image];
backgroundView.tag = 1;
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];
}
}
//for other views
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index
{
[super insertSubview:view atIndex:index];
[self sendSubviewToBack:backgroundView];
}
@end
//YourViewController.m
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar
setBackgroundImage:[UIImage imageNamed:@"navigation_bar_bg.png"]];
}
@interface UINavigationBar (UINavigationBarCategory)
UIImageView *backgroundView;
- (void)setBackgroundImage:(UIImage*)image;
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
@end
//CustomNavigationBar.m
@implementation UINavigationBar (UINavigationBarCategory)
-(void)setBackgroundImage:(UIImage*)image
{
if(image == nil)
{
[backgroundView removeFromSuperview];
}
else
{
backgroundView = [[UIImageView alloc] initWithImage:image];
backgroundView.tag = 1;
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];
}
}
//for other views
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index
{
[super insertSubview:view atIndex:index];
[self sendSubviewToBack:backgroundView];
}
@end
//YourViewController.m
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar
setBackgroundImage:[UIImage imageNamed:@"navigation_bar_bg.png"]];
}
相关文章推荐
- iphone 表格背景透明
- iPhone http Post数据
- 让新手也会破解 超详细iPhone全破解教程
- 提交iPhone app程序遇到newss…
- 打电话不是梦iPod Touch摇身变iPhone
- 不当板砖 iPhone1.1.3降级1.1.1固件教程
- 新3分钟搞定 iPhone1.1.2/1.1.3软破教程
- iphone之MPMoviePlayer 视频…
- iPhone NSUserDefaults 保存数据
- IOS 5 设置NavigationBar 背景
- iPhone PC Suite上传铃声法(支持iPhone v1.1.1)
- iPhone使用大全第二讲《Installer 3》
- iPhone LumaQQ聊天软件详细使用教程
- 1.1.4 iPhone系统固件制作教程(Mac)
- iphone touchjson
- iPhone入门 - UIAlertView用法
- 改变word 、 txt等背景颜色的设置…
- port iphone app to ipad
- iphone 自定义导航栏按钮
- AnySim一键解锁教程 只适用于新iPhone