1

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 ?

  • Possible duplicate of [iPhone X status bar height](https://stackoverflow.com/questions/46775477/iphone-x-status-bar-height) – user6788419 Nov 10 '17 at 12:02

2 Answers2

1

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

UIApplication.sharedApplication.statusBarFrame.size.height
Tj3n
  • 9,837
  • 2
  • 24
  • 35
-1

Change this line.

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;
}

With this one:

if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone) {
  // determine screen size
int screenHeight = [UIScreen mainScreen].bounds.size.height;

switch (screenHeight) {
        // iPhone 5s
    case 568:
        NSLog(@"iPhone 5 or 5S or 5C");
        break;
        // iPhone 6
    case 667:
        NSLog(@"iPhone 6/6S/7/8");
        break;
        // iPhone 6 Plus
    case 736:
        NSLog(@"iPhone 6+/6S+/7+/8+");
        break;
        // iPhone X
    case 814:
        NSLog(@"iPhone X");
        break;
    default:
        // it's an iPad
        printf("unknown");
}

}
Mukesh
  • 777
  • 7
  • 20