iOS Dev Nugget 80 Switching UIStatusBarStyle Based on UIImage Shown


Need to run a code review on your codebase? Hire me

Ever built an app which displays photos and can’t decide which is the best UIStatusBarStyle to use, because there isn’t one that will work with every photo?

Max Howell (who wrote Homebrew) has 2 Cocoapods that will help with that:

Combining them, you can use the luminance of the UIImage instance to figure out whether UIStatusBarStyleLightContent or UIStatusBarStyleDefault is more appropriate:

#import "UIImage+AverageColor.h"
#import "UIColor+PerceivedLuminance.h"

@implementation MyViewController

- (UIStatusBarStyle)preferredStatusBarStyle {
    return self.topImageView.image.averageColor.perceivedLuminance > 0.5
        ? UIStatusBarStyleLightContent
        : UIStatusBarStyleDefault;


Try it out.

Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No



Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter


View archives of past issues