8

I can get the status bar from UIApplication in normal app by

[UIApplication sharedApplication].statusBarFrame

But we cannot access UIApplication from Extension.Is there a way to find get the statusbar in share?

guhan0
  • 666
  • 6
  • 19
  • why you want the status bar height anyway, it's always 20 in all the devices. – Kiran Jasvanee Feb 04 '16 at 09:34
  • what kinda extension does it require to know about the status bar's frame? – holex Feb 04 '16 at 09:36
  • I am using the height for custom animation for that viewcontroller.any way i found that there is no meaning in getting status bar from extension.hence i have to alter the animation thing. – guhan0 Feb 04 '16 at 09:53
  • 2
    kiran it's not 20 if the user is on a call. and sometimes it's 0. – crgt Jul 19 '16 at 17:37

2 Answers2

1

You may use safeAreaLayoutGuide to calculate layout frame. eg,

viewController.view.safeAreaLayoutGuide.layoutFrame.minY
Jerome Li
  • 1,492
  • 14
  • 20
0

Alternate Option:

If you're using a view controller with NavigationBar, you can consider its y position as the StatusBar height, in case safeAreaLayoutGuide and window?.windowScene?.statusBarManager?.statusBarFrame.height options were not available or usable.

let statusBarHeight = navigationController?.navigationBar.frame.origin.y ?? 0
Anusha Kottiyal
  • 3,855
  • 3
  • 28
  • 45