Why cornerRadius and maskToBounds properties won't affect statusBar if I set background color for statusBar?
(I'm a beginner in swift)
CONTEXT
What I want to achieve:
I want to set cornerRadius for every corner of the screen within the app.
What have I done so far?:
// I added the following in appDelegate:didFinishLaunchingWithOptions
self.window?.layer.cornerRadius = 20
self.window?.layer.masksToBounds = true
It works fine in every corner of the screen IF statusBar doesn't have background color.
If backgroundColor is set for statusBar, only the bottom corners of the screen will be rounded.
What I suspect is failing: I suspect the statusBar is within a layer on top of the layer that holds the window in which I'm setting the cornerRadius property and that's why it doesn't render with that property. If statusBar has no backgroundColor (.clear) it doesn't cover the window, so I can see the 4 corners rounded in the screen.
That's why I tried to set statusBar's cornerRadius property:
// Still in appDelegate:didFinishLaunchingWithOptions
UIApplication.shared.statusBarView?.layer.cornerRadius = 20
UIApplication.shared.statusBarView?.layer.masksToBounds = true
UIApplication.shared.statusBarView?.backgroundColor = .blue
self.window?.layer.cornerRadius = 20
self.window?.layer.masksToBounds = true
It does round the corners in statusBar if its value is lower than its height, BUT if cornerRadius value is higher than statusBar's height it starts to behave weird, leaving some black space between itself and the navigationBar.
Is there a way to set a "global mask" or "global property" that also affects statusBar?
I thought that by only setting cornerRadius for top corners would work, but, again, if cornerRadius is higher that its height, it renders leaving some unwanted blank space.
Suggestions to achieve what I want in other ways are welcome
Thank you :)