OStack程序员社区-中国程序员成长平台

标题: ios - UIKIt - 删除状态栏但留下空间 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 20:52
标题: ios - UIKIt - 删除状态栏但留下空间

我知道如何删除状态栏,但这会自动将我的导航 Controller 及其导航栏捕捉到屏幕顶部。

如何移除状态栏但在屏幕顶部保留 20 像素的空间,以便我可以在该空间中放置自己的自定义 View 或窗口?



Best Answer-推荐答案


创建自定义 UINavigationController 并覆盖 viewDidAppear

    - (void)viewDidAppearBOOL)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];
    }

关于ios - UIKIt - 删除状态栏但留下空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22703303/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4