我知道如何删除状态栏,但这会自动将我的导航控制器及其导航栏捕捉到屏幕顶部。
如何删除状态栏但保留屏幕顶部的20 px空间,以便将自己的自定义视图或窗口放在该空间中?
答案 0 :(得分:1)
创建自定义UINavigationController并覆盖viewDidAppear
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGRect f = self.view.frame;
self.view.frame = CGRectMake(0,20,f.size.width,f.size.height-20);
//the custom view for replacing the status bar.
//you can add any custom subview you want
UIView *iv = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,20)];
//assign a color with alpha less than 1.0 to make it translucent
iv.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
//remember to remove the iv when you don't need the navigation controller any more.
[self.view.window insertSubview:iv aboveSubview:self.view];
}