通過滑動界面,根據偏移量 實時修改頂部statusBarStyle(電池條)顏色。 直接上代碼:
首先將info.plist文件中View controller-based status bar appearance這個參數設置為NO。
其次在scrollView的代理方法裡設置樣式即可
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
_content = scrollView.contentOffset.y;
_navview.alpha = _content / 200;
if (_navview.alpha > 0) {
return [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];//黑色
}
return [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];//白色
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//設置電池條為黑色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
}