当点击搜索时 导航栏消失 当时状态栏位置会留在20像素 此时状态栏风格与导航栏不一致 因此需要设置状态栏背景
方法:
首先要把这20像素弄没再自己添加20个进去 就可以自定义背景了
首先 在didload里添加 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = YES;
self.modalPresentationCapturesStatusBarAppearance = NO;
self.automaticallyAdjustsScrollViewInsets = YES;
}
这是变成
再
- (void) viewDidLayoutSubviews {
CGRect viewBounds = self.view.bounds;
CGFloat topBarOffset = self.topLayoutGuide.length;
viewBounds.origin.y = topBarOffset * -1;
self.view.bounds = viewBounds;
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"searchbar_bg@2x.png"]];
}
就达到了这样的效果