Search code examples
iosobjective-cmmdrawercontroller

Change status bar height, based on if the device is an iPhone X or not


In my application, I use a custom pod called MMDrawerController, to create a dummy status bar, unfortunately in the pod the status bar's height is always set to 20.

In order to fix this issue I have written the following code:

App delegate

MMDrawerController *mmdrawer = [[MMDrawerController alloc]init];


//UPDATE IPHONE X STATUS BAR
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    if (screenSize.height == 812.0f) {
        NSLog(@"DEVICE NAME : iPhone X");
        self.iphoneXHeight = -45.0;
        self.iphoneXHeightPos = 45.0;
        mmdrawer.height = 40;
    }
    else {

        self.iphoneXHeight = -20.0;
        self.iphoneXHeightPos = 20.0;
        mmdrawer.height = 20;


    }
}

MMDrawerController.h

@property (nonatomic,assign) CGFloat height;

MMDrawerController.m

  _dummyStatusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), self.height)];

Problem:

When I run my code the height property is always 0, would appreciate it if someone can point out what I am doing wrong here and how would I be able access the height property and modify it ?


Solution

  • Dont use fixed height for the status bar, you can get the height with this code:

    UIApplication.sharedApplication.statusBarFrame.size.height