guhan0
guhan0

Reputation: 676

How to get the status bar height in iOS Extension

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?

Upvotes: 8

Views: 946

Answers (2)

Anusha Kottiyal
Anusha Kottiyal

Reputation: 3905

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

Upvotes: 0

Jerome Li
Jerome Li

Reputation: 1586

You may use safeAreaLayoutGuide to calculate layout frame. eg,

viewController.view.safeAreaLayoutGuide.layoutFrame.minY

Upvotes: 1

Related Questions