11

The issue is simple :

  • The Application is based on UITabBarViewController
  • 3 Tabs in the controllers
  • TabBar Views are configured in viewDidLoad for the UITabBarViewController

On launch, the UIStatusBar appear in Black background color Launch Status Bar

Changing to any tab the UIStatusBar get colored!

Correct Status Bar

What I'm missing?

JAL
  • 41,701
  • 23
  • 172
  • 300
OXXY
  • 1,047
  • 2
  • 18
  • 43
  • Do you have any code in your view controller modifying the status bar appearance? – JAL Oct 19 '17 at 15:40
  • @JAL not a single word! – OXXY Oct 19 '17 at 19:11
  • Well, I'm not sure then. I experienced a similar issue unrelated to `UITabBar`. I'm not sure it applies to you, but I've added an answer anyways. Maybe it will help someone else who runs into this issue. – JAL Oct 19 '17 at 19:12

4 Answers4

1

I had a similar issue some months ago - I solved it by adding the following lines into my AppDelegate. Please find below my swift code, I'm sure you know the objective-c syntax:

    // Setup general NavBar appearance
    UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
    UINavigationBar.appearance().shadowImage = UIImage()
    UINavigationBar.appearance().backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
    UINavigationBar.appearance().isTranslucent = true
    UINavigationBar.appearance().tintColor = UIColor.white
    UIApplication.shared.statusBarStyle = .lightContent // => this would be the solution

I think the last line of code would be interesting for you. It's important to set this changes in your AppDelegate.

AlexWoe89
  • 844
  • 1
  • 11
  • 23
0

I had a similar issue. While not directly related the OP's issue with the tab bar, I too saw that my translucent status bar had appeared to turn opaque and was pushing the view down.

After migrating my project from Swift 3 with Xcode 8 to Swift 4 with Xcode 9, I started experiencing this same issue where the status bar appeared to be pushing content down when it was visible. At first I thought it was an issue with the preferred UIStatusBarStyle I had set (I was using UIStatusBarStyleLightContent), but that was working correctly.

The issue was that in the move from Xcode 8 to 9, a subview in one of my view controllers was misplaced in the Storyboard. A constraint that previously pinned that view to the top of the view controller was pointing incorrectly pointing to the View (with margins) instead of the Top Layout Guide. Switching this constraint to use the Top Layout Guide with a value of 0 solved my problem.

Storyboard

JAL
  • 41,701
  • 23
  • 172
  • 300
  • I'm Building this project with Objective C and genuinely on this XCode not migrating any part! Again the problem appears in the navigationControllers inside the TabBarController! – OXXY Oct 19 '17 at 19:12
0

In didFinishLaunchingWithOptions method set status bar style to light content

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[application setStatusBarStyle:UIStatusBarStyleLightContent];

and in every viewController return this :

-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}

or if you are using the UINavigationController then also add this line of code in every viewController (or make a baseViewController) viewWillAppear method

- (void)viewWillAppear:(BOOL)animated{

[super viewWillAppear:animated];

self.navigationController.navigationBar.barStyle = UIStatusBarStyleLightContent;
JAL
  • 41,701
  • 23
  • 172
  • 300
iamVishal16
  • 1,780
  • 18
  • 40
  • Thank you so much for your response. My problem isn't in status bar style the problem is in the position of the navigation controller and the background of the status bar.! – OXXY Oct 25 '17 at 07:40
0

For me following approach is working

final class StatusbarStyle {
    static let shared = StatusbarStyle()
    var style:UIStatusBarStyle = .default
}

and then whenever I need to change status bar color I write following:

StatusbarStyle.shared.style = .default
navigationController?.setNeedsStatusBarAppearanceUpdate()
Roma
  • 1,107
  • 9
  • 19