0

I already asked this question but no answer helped my. So I'm trying it again:

I want to have a custom background color (e.g. red) for the status bar in all my ViewControllers. The ViewControllers are managed by a TabBarController. Status Bar (and its background) shall only be shown in portrait mode, on iPhone. On iPad Status Bar should be shown always.

I'm using Swift for my project.

Does anybody know how to do that? Maybe anybody has a code sample?

  • The status bar's background is transparent. You can place a view below it to give the appearance of a background. http://stackoverflow.com/questions/30341224/ios-custom-status-bar-background-color-not-displaying?rq=1 – beyowulf Jun 06 '16 at 16:50
  • I already tried it. It was my first idea before googling. But unfortunately this View doesn't disappear in landscape mode. Status bar disappears in landscape mode bus the View stays. Do you know a solution to hide this View in landscape? I also tried to set the background color of the whole View (ViewController) but same problem here: Status Bar disappears in landscape (as wished) but the colored stripe on the top stays. –  Jun 06 '16 at 16:52
  • see http://stackoverflow.com/questions/26943808/ios-how-to-run-a-function-after-device-has-rotated-swift in Acey's answer where it says "// Your code here" check the orientation and move the view off screen if necessary. – beyowulf Jun 06 '16 at 17:00
  • It seems like the view disappears automatically in landscape. It seems like I have to "Clear Constraints" in whole ViewController and the "Add missing Constraints". –  Jun 06 '16 at 17:25
  • I don't know what that means. When I said "move the view off screen," I meant "the colored stripe on the top." So, I'm not sure how it stays and disappears automatically. If you don't want to fuss with constraints, you could just set its alpha to 0. For example `self.statusBarBackground.alpha = (self.traitCollection.userInterfaceIdiom == .Phone && size.width > size.height) ? 0.0 : 1.0` – beyowulf Jun 06 '16 at 17:36
  • I already solved the problem by putting a UIView below the Status bar and set the background color. But I had to clear all constraints and add them again to make the UIView hiding in landscape mode. –  Jun 06 '16 at 17:38
  • So it's working for you? – beyowulf Jun 06 '16 at 19:01
  • Yes, it is. Why are you asking? Is that surprising? –  Jun 06 '16 at 19:02
  • Great! congrats. I'm just trying to follow the conversation. – beyowulf Jun 06 '16 at 19:04
  • Okay, it's really working. But don't forget: You maybe have to clear an add all constraints of the ViewController again. Otherwise the UIView will not disappear in landscape mode. –  Jun 06 '16 at 19:05

0 Answers0