Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Code for contrasting status bar style breaks status bar style on navigation controllers, even if not using contrasting status bar style. #95

Closed
gbegen opened this issue Dec 18, 2015 · 6 comments

Comments

@gbegen
Copy link

gbegen commented Dec 18, 2015

Based on this StackOverflow answer, we set navigationBar.barStyle on our UINavigationController to control the status bar style. When we added Chameleon, we started getting incorrect status bar coloring even though we never used Chameleon to set a contrasting status bar style anywhere in our app.

I think that https://github.com/ViccAlexander/Chameleon/blob/master/Pod/Classes/Objective-C/UIViewController%2BChameleon.m#L125 should store the return value from the original method that was swizzled away and return it at https://github.com/ViccAlexander/Chameleon/blob/master/Pod/Classes/Objective-C/UIViewController%2BChameleon.m#L140 instead of always returning UIStatusBarStyleDefault.

@vicc
Copy link
Owner

vicc commented Jan 7, 2016

That seems to make sense. Thanks for this. I'll try to update it asap.

@aocenas
Copy link

aocenas commented Jan 21, 2016

I do not usually leave +1s as I know nobody really likes them, but I spent literally hours trying to change status bar color, using different approaches and their combinations until I found out this was the issue. I use chameleon mainly for flat colors and some utils, and it is definitely great piece of work, but I did not even know that it adds some code to UINavigationController (my bad not reading all the docu, but I think I am not the only one) and so did not even think to look here. So yeah this time I would like to +1 this as it is not trivial to find out where the problem actually is.

@vicc
Copy link
Owner

vicc commented Jan 22, 2016

@aocenas I find +1's super helpful! They help prioritize issues. With that said, sorry for the trouble. 😞 I'll definitely update this over the weekend, along with a few other things.

vicc added a commit that referenced this issue Jan 25, 2016
• Fixed issue where Chameleon would override the preferred
statusBarStyle even when not being asked to (bad Chameleon!)
• Added ability to retrieve the hexString value for any color. Note: I
needed this recently, so I figured some of you might find it useful as
well!!! (i.e. [coolNewColor hexStringValue];
• Added some new methods for generating random colors.
• Added an Objective-c demo project.
@vicc
Copy link
Owner

vicc commented Jan 25, 2016

@gbegen @aocenas Let me know of the issue has been resolved in 2.1.0

@aocenas
Copy link

aocenas commented Jan 26, 2016

@ViccAlexander still does not seem to be fixed. This is the code I am using for testing:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        let ctrl = UIViewController()
        let navCtrl = UINavigationController(rootViewController: ctrl)
        navCtrl.navigationBar.barStyle = .Black
        navCtrl.navigationBar.barTintColor = UIColor.grayColor()
        navCtrl.navigationBar.translucent = false
        window!.rootViewController = navCtrl
        window!.makeKeyAndVisible()

        return true
    }

Using navigationBar.barStyle seems like the correct way to do this (http://stackoverflow.com/a/19513714). This code still generates white status bar without chamelon, but black status bar with chameleon 2.1.0 installed.

@onomated
Copy link

onomated commented May 7, 2016

@aocenas Had the same issue with chameleon 2.1.0 as well. After debugging for a while, I found that you also have to set the navigation controller status bar style in chameleon.

In my case, in Obj-C this worked for me:

            [self.navigationController setStatusBarStyle:UIStatusBarStyleDefault];
            self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

@vicc vicc closed this as completed Sep 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants