您的位置:首页 > 其它

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"]];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: