🚀 UllrichLumina

iOS 7 status bar back to iOS 6 default style in iPhone app

iOS 7 status bar back to iOS 6 default style in iPhone app

📅 | 📂 Category: Programming

iOS 7 marked a significant shift in Apple’s design philosophy, introducing a flatter, more minimalist aesthetic. While many embraced the change, some users, particularly developers, found themselves grappling with the updated status bar. Its translucent nature and integration with the app’s background presented challenges for maintaining a clear separation between content and system information. This often led to readability issues and a desire to revert to the distinct, solid status bar of iOS 6. This article explores how to achieve that classic iOS 6 status bar look within your iPhone app, offering practical solutions and code examples to help you enhance user experience and maintain design consistency.

Understanding the iOS 7 Status Bar Challenge

The translucent status bar in iOS 7 blurred the lines between app content and system information, sometimes leading to poor contrast and readability. Imagine a light-colored background in your app clashing with white status bar icons. This made it difficult for users to discern important information like battery life or signal strength. Developers needed a way to regain control over this critical interface element.

Furthermore, the integrated design sometimes clashed with existing app aesthetics, particularly those designed with the solid iOS 6 status bar in mind. The shift required developers to rethink their layouts and color palettes, often leading to significant rework.

One of the key challenges was ensuring compatibility with different app designs and background colors. A solution that worked well for one app might not be suitable for another, necessitating a flexible and adaptable approach.

Recreating the iOS 6 Status Bar Look

Fortunately, several techniques emerged to address the iOS 7 status bar challenges and restore the familiar iOS 6 style. One common method involves adding a solid-colored view behind the status bar, effectively mimicking the older, opaque look.

Here’s a code snippet demonstrating how to add a solid black status bar in Objective-C:

// Objective-C UIView statusBarBackground = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)]; statusBarBackground.backgroundColor = [UIColor blackColor]; [self.view addSubview:statusBarBackground]; 

This code creates a new UIView and positions it at the top of the screen, effectively covering the translucent status bar with a solid black background. You can customize the color to match your app’s design.

Advanced Status Bar Customization

Beyond simply adding a solid background, developers can leverage more advanced techniques for finer control over the status bar appearance. This includes changing the status bar style to either light or dark content, depending on the app’s background color, to maintain optimal readability.

Here’s how to set the status bar style to light content in Swift:

// Swift override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } 

This code snippet ensures that status bar icons appear in a light color, making them clearly visible against a darker background. This approach provides greater flexibility and control, allowing developers to tailor the status bar to specific app designs.

Best Practices for Status Bar Management

When managing the status bar, consider the overall user experience. Ensure sufficient contrast between the status bar and the app’s background for optimal readability. Test your implementation thoroughly across different devices and iOS versions to ensure consistent behavior. Refer to Apple’s Human Interface Guidelines for recommendations on status bar usage.

For more in-depth information, you can explore resources like Apple’s Developer Documentation and Stack Overflow.

  • Maintain contrast for readability.
  • Test thoroughly across devices.
  1. Determine your desired status bar style.
  2. Implement the appropriate code.
  3. Test on various devices and backgrounds.

Consider using a third-party library like this example status bar library (replace with a real library) for more advanced customization options.

Leveraging Third-Party Libraries

Several third-party libraries offer pre-built solutions for customizing the status bar. These libraries often simplify the implementation process and provide additional features beyond the standard iOS SDK capabilities. They can be particularly helpful for complex status bar manipulations or for maintaining consistency across different iOS versions.

See this internal link for related styling tips.

Infographic Placeholder: [Insert infographic illustrating different status bar styles and their impact on readability]

FAQ: What if my app uses a dynamic background color? In cases with dynamic backgrounds, update the status bar style accordingly using code within your view controller’s viewWillAppear method. This ensures the status bar remains visually consistent as the background changes.

By understanding the challenges presented by the iOS 7 status bar and employing the techniques outlined in this article, developers can effectively recreate the classic iOS 6 look and feel within their iPhone apps. This allows for greater design consistency, improved readability, and an enhanced user experience. Remember to prioritize user needs and strive for a visually appealing and functional interface. Explore the provided resources and experiment with different approaches to find the best solution for your specific app design. Implementing these strategies can significantly impact your app’s visual appeal and usability. Take the time to refine your status bar implementation and reap the benefits of a polished and user-friendly interface.

Question & Answer :
In iOS 7 the UIStatusBar has been designed in a way that it merges with the view like this:

GUI designed by Tina Tavčar (GUI designed by Tina Tavčar)

  • It is cool, but it will somewhat mess up your view when you have something at the top part of your view, and it becomes overlapped with the status bar.
  • Is there a simple solution (such as setting a property in info.plist) that can change the way it works [not overlapping] back to how it is in iOS6?
  • I know a more straightforward solution is to have self.view.center.x + 20 points for every single view controller, but changing them will screw other dimensions up (having a different self.view.center.x can cause problem to custom segues, etc.) and suddenly it turns into a tedious job that is best to be avoided.
  • I’ll really be glad if someone can provide me an one-liner solution for this.

P.S. I know I can hide the status bar by doing things like having

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; 

In didFinishLaunchingWithOptions method, but that’s a workaround, a shortcut avoiding the problem, so I don’t consider that a real solution.

This is cross-posted from a blog post I wrote, but here is the full rundown on status bars, navigation bars, and container view controllers on iOS 7:

  1. There is no way to preserve the iOS 6 style status bar layout. The status bar will always overlap your application on iOS 7
  2. Do not confuse status bar appearance with status bar layout. The appearance (light or default) does not affect how the status bar is laid out (frame/height/overlap). It is important to note as well that the system status bar no longer has any background color. When the API refers to UIStatusBarStyleLightContent, they mean white text on a clear background. UIStatusBarStyleDefault is black text on a clear background.
  3. Status bar appearance is controlled along one of two mutually-exclusive basis paths: you can either set them programmatically in the traditional manner, or UIKit will update the appearance for you based on some new properties of UIViewController. The latter option is on by default. Check your app’s plist value for “ViewController-Based Status Bar Appearance” to see which one you’re using. If you set this value to YES, every top-level view controller in your app (other than a standard UIKit container view controller) needs to override preferredStatusBarStyle, returning either the default or the light style. If you edit the plist value to NO, then you can manage the status bar appearance using the familiar UIApplication methods.
  4. UINavigationController will alter the height of its UINavigationBar to either 44 points or 64 points, depending on a rather strange and undocumented set of constraints. If the UINavigationController detects that the top of its view’s frame is visually contiguous with its UIWindow’s top, then it draws its navigation bar with a height of 64 points. If its view’s top is not contiguous with the UIWindow’s top (even if off by only one point), then it draws its navigation bar in the “traditional” way with a height of 44 points. This logic is performed by UINavigationController even if it is several children down inside the view controller hierarchy of your application. There is no way to prevent this behavior.
  5. If you supply a custom navigation bar background image that is only 44 points (88 pixels) tall, and the UINavigationController’s view’s bounds matches the UIWindow’s bounds (as discussed in #4), the UINavigationController will draw your image in the frame (0,20,320,44), leaving 20 points of opaque black space above your custom image. This may confuse you into thinking you are a clever developer who bypassed rule #1, but you are mistaken. The navigation bar is still 64 points tall. Embedding a UINavigationController in a slide-to-reveal style view hierarchy makes this abundantly clear.
  6. Beware of the confusingly-named edgesForExtendedLayout property of UIViewController. Adjusting edgesForExtendedLayout does nothing in most cases. The only way UIKit uses this property is if you add a view controller to a UINavigationController, then the UINavigationController uses edgesForExtendedLayout to determine whether or not its child view controller should be visible underneath the navigation bar / status bar area. Setting edgesForExtendedLayout on the UINavigationController itself does nothing to alter whether or not the UINavigationController has a 44 or 64 point high navigation bar area. See #4 for that logic. Similar layout logic applies to the bottom of your view when using a toolbar or UITabBarController.
  7. If all you are trying to do is prevent your custom child view controller from underlapping the navigation bar when inside a UINavigationController, then set edgesForExtendedLayout to UIRectEdgeNone (or at least a mask that excludes UIRectEdgeTop). Set this value as early as possible in the life cycle of your view controller.
  8. UINavigationController and UITabBarController will also try to pad the contentInsets of table views and collection views in its subview hierarchy. It does this in a manner similar to the status bar logic from #4. There is a programmatic way of preventing this, by setting automaticallyAdjustsScrollViewInsets to NO for your table views and collection views (it defaults to YES). This posed some serious problems for Whisper and Riposte, since we use contentInset adjustments to control the layout of table views in response to toolbar and keyboard movements.
  9. To reiterate: there is no way to return to iOS 6 style status bar layout logic. In order to approximate this, you have to move all the view controllers of your app into a container view that is offset by 20 points from the top of the screen, leaving an intentionally black view behind the status bar to simulate the old appearance. This is the method we ended up using in Riposte and Whisper.
  10. Apple is pushing very hard to ensure that you don’t try to do #9. They want us to redesign all our apps to underlap the status bar. There are many cogent arguments, however, for both user experience and technical reasons, why this is not always a good idea. You should do what is best for your users and not simply follow the whimsy of the platform.