先看下效果图:并没有做滚动显示导航栏,下次补上!
相关代码如下:
先设置一个自定义背景图片
@property (nonatomic ,strong) UIImageView * imageViewBar;
-(void)viewDidLoad{
其他配置
[self setNaVationBar];
}
- (void)setNaVationBar {
// 透明状态栏的延伸
self.edgesForExtendedLayout = UIRectEdgeNone;
//可有可无
[self.navigationController.navigationBar setBackgroundImage:nil
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
//一条线
self.navigationController.navigationBar.shadowImage = [UIImage new];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//设置状态栏背景字体颜色
//(图片设置会导致全局白字,下面这句可以在个别界面设置成黑字)
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
//导航栏透明设置
self.imageViewBar = self.navigationController.navigationBar.subviews.firstObject;
self.imageViewBar.alpha = 0;
}
- (void)viewWillDisappear:(BOOL)animated {
//恢复白色
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
//恢复不透明
self.imageViewBar.alpha = 1;
}