導航欄透明漸變
阿新 • • 發佈:2019-01-24
1,導航欄透明
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
2,漸變
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
UIImageView *barImageView = self.navigationController.navigationBar.subviews.firstObject;
CGFloat minAlphaOffset = - 64;
CGFloat maxAlphaOffset = 200;
CGFloat offset = scrollView.contentOffset.y;
CGFloat alpha = (offset - minAlphaOffset) / (maxAlphaOffset - minAlphaOffset);
barImageView.alpha = alpha;
}
3,狀態列和標題的顏色
//狀態列
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
//標題顏色
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor someColor]}
//導航欄子控制元件顏色
self.navigationController.navigationBar.tintColor = [UIColor someColor];
4,釋放tableView 的 delegate(不然你進進出出時候會發現哪裡好像不太對)
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tableView.delegate = self;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.tableView.delegate = nil;
}
5,導航欄是公有的
需要在ViewWillDisappear裡面再把導航欄設定