Attempting to Change the UIStatusBar Tint Color












2















I am trying to change the UIStatusBar tint color in a specific UIViewController.



Here is my code:



override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)

self.setNeedsStatusBarAppearanceUpdate()

}


Nothing is happening.










share|improve this question

























  • Possible duplicate of preferredStatusBarStyle isn't called

    – Damon
    Nov 24 '18 at 11:11











  • @Damon, while I could agree that this may be a dup, that one has much more details than this one - including the specifics that we are talking a UINavigationController scenario. SO far, the OP has only said "in a specific VC". TO the OP, could you provide more specifics? I've successfully overriden preferredStatusBarStyle many time. It doesn't need a call to setNeedsStatusBarAppearanceUpdate under most circumstances (including setting things in every VC depending o how you set it the first time). If you copy/paste the posted code into a new project, does it work?

    – dfd
    Nov 24 '18 at 11:51
















2















I am trying to change the UIStatusBar tint color in a specific UIViewController.



Here is my code:



override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)

self.setNeedsStatusBarAppearanceUpdate()

}


Nothing is happening.










share|improve this question

























  • Possible duplicate of preferredStatusBarStyle isn't called

    – Damon
    Nov 24 '18 at 11:11











  • @Damon, while I could agree that this may be a dup, that one has much more details than this one - including the specifics that we are talking a UINavigationController scenario. SO far, the OP has only said "in a specific VC". TO the OP, could you provide more specifics? I've successfully overriden preferredStatusBarStyle many time. It doesn't need a call to setNeedsStatusBarAppearanceUpdate under most circumstances (including setting things in every VC depending o how you set it the first time). If you copy/paste the posted code into a new project, does it work?

    – dfd
    Nov 24 '18 at 11:51














2












2








2








I am trying to change the UIStatusBar tint color in a specific UIViewController.



Here is my code:



override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)

self.setNeedsStatusBarAppearanceUpdate()

}


Nothing is happening.










share|improve this question
















I am trying to change the UIStatusBar tint color in a specific UIViewController.



Here is my code:



override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)

self.setNeedsStatusBarAppearanceUpdate()

}


Nothing is happening.







swift uistatusbar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 13:27









wvteijlingen

8,61612544




8,61612544










asked Nov 24 '18 at 11:04









CallumCallum

348114




348114













  • Possible duplicate of preferredStatusBarStyle isn't called

    – Damon
    Nov 24 '18 at 11:11











  • @Damon, while I could agree that this may be a dup, that one has much more details than this one - including the specifics that we are talking a UINavigationController scenario. SO far, the OP has only said "in a specific VC". TO the OP, could you provide more specifics? I've successfully overriden preferredStatusBarStyle many time. It doesn't need a call to setNeedsStatusBarAppearanceUpdate under most circumstances (including setting things in every VC depending o how you set it the first time). If you copy/paste the posted code into a new project, does it work?

    – dfd
    Nov 24 '18 at 11:51



















  • Possible duplicate of preferredStatusBarStyle isn't called

    – Damon
    Nov 24 '18 at 11:11











  • @Damon, while I could agree that this may be a dup, that one has much more details than this one - including the specifics that we are talking a UINavigationController scenario. SO far, the OP has only said "in a specific VC". TO the OP, could you provide more specifics? I've successfully overriden preferredStatusBarStyle many time. It doesn't need a call to setNeedsStatusBarAppearanceUpdate under most circumstances (including setting things in every VC depending o how you set it the first time). If you copy/paste the posted code into a new project, does it work?

    – dfd
    Nov 24 '18 at 11:51

















Possible duplicate of preferredStatusBarStyle isn't called

– Damon
Nov 24 '18 at 11:11





Possible duplicate of preferredStatusBarStyle isn't called

– Damon
Nov 24 '18 at 11:11













@Damon, while I could agree that this may be a dup, that one has much more details than this one - including the specifics that we are talking a UINavigationController scenario. SO far, the OP has only said "in a specific VC". TO the OP, could you provide more specifics? I've successfully overriden preferredStatusBarStyle many time. It doesn't need a call to setNeedsStatusBarAppearanceUpdate under most circumstances (including setting things in every VC depending o how you set it the first time). If you copy/paste the posted code into a new project, does it work?

– dfd
Nov 24 '18 at 11:51





@Damon, while I could agree that this may be a dup, that one has much more details than this one - including the specifics that we are talking a UINavigationController scenario. SO far, the OP has only said "in a specific VC". TO the OP, could you provide more specifics? I've successfully overriden preferredStatusBarStyle many time. It doesn't need a call to setNeedsStatusBarAppearanceUpdate under most circumstances (including setting things in every VC depending o how you set it the first time). If you copy/paste the posted code into a new project, does it work?

– dfd
Nov 24 '18 at 11:51












3 Answers
3






active

oldest

votes


















1














On a UINavigationController, preferredStatusBarStyle is not called because its topViewController is preferred to self. So, to get preferredStatusBarStyle called on an UINavigationController, you need to change its childViewControllerForStatusBarStyle.



To do it for one UINavigationController:



class MyRootNavigationController: UINavigationController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override var childViewControllerForStatusBarStyle: UIViewController? {
return nil
}
}





share|improve this answer































    0














    You can add an extension to UINavigationController:



    extension UINavigationController {
    open override var childForStatusBarStyle: UIViewController? {
    return visibleViewController
    }
    }


    Then for view controllers that you want a light status bar (white time, icons etc.), then override preferredStatusBarStyle:



    override var preferredStatusBarStyle: UIStatusBarStyle {
    return UIStatusBarStyle.lightContent
    }


    For a dark status bar, you don't have to do anything.






    share|improve this answer
























    • Where do I put this extension?

      – Callum
      Nov 25 '18 at 11:06











    • Anywhere you want :) You can put it below your entire view controller (not in the same class). If you want to be more organised and avoid a large file, you can put it in it's own file

      – Matt Le Fleur
      Nov 26 '18 at 12:15



















    0














    You may need to add "View controller-based status bar appearance" with a value of "YES" in your info.plist






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457475%2fattempting-to-change-the-uistatusbar-tint-color%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      On a UINavigationController, preferredStatusBarStyle is not called because its topViewController is preferred to self. So, to get preferredStatusBarStyle called on an UINavigationController, you need to change its childViewControllerForStatusBarStyle.



      To do it for one UINavigationController:



      class MyRootNavigationController: UINavigationController {
      override var preferredStatusBarStyle: UIStatusBarStyle {
      return .lightContent
      }
      override var childViewControllerForStatusBarStyle: UIViewController? {
      return nil
      }
      }





      share|improve this answer




























        1














        On a UINavigationController, preferredStatusBarStyle is not called because its topViewController is preferred to self. So, to get preferredStatusBarStyle called on an UINavigationController, you need to change its childViewControllerForStatusBarStyle.



        To do it for one UINavigationController:



        class MyRootNavigationController: UINavigationController {
        override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
        }
        override var childViewControllerForStatusBarStyle: UIViewController? {
        return nil
        }
        }





        share|improve this answer


























          1












          1








          1







          On a UINavigationController, preferredStatusBarStyle is not called because its topViewController is preferred to self. So, to get preferredStatusBarStyle called on an UINavigationController, you need to change its childViewControllerForStatusBarStyle.



          To do it for one UINavigationController:



          class MyRootNavigationController: UINavigationController {
          override var preferredStatusBarStyle: UIStatusBarStyle {
          return .lightContent
          }
          override var childViewControllerForStatusBarStyle: UIViewController? {
          return nil
          }
          }





          share|improve this answer













          On a UINavigationController, preferredStatusBarStyle is not called because its topViewController is preferred to self. So, to get preferredStatusBarStyle called on an UINavigationController, you need to change its childViewControllerForStatusBarStyle.



          To do it for one UINavigationController:



          class MyRootNavigationController: UINavigationController {
          override var preferredStatusBarStyle: UIStatusBarStyle {
          return .lightContent
          }
          override var childViewControllerForStatusBarStyle: UIViewController? {
          return nil
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 12:28









          AmmarAmmar

          1929




          1929

























              0














              You can add an extension to UINavigationController:



              extension UINavigationController {
              open override var childForStatusBarStyle: UIViewController? {
              return visibleViewController
              }
              }


              Then for view controllers that you want a light status bar (white time, icons etc.), then override preferredStatusBarStyle:



              override var preferredStatusBarStyle: UIStatusBarStyle {
              return UIStatusBarStyle.lightContent
              }


              For a dark status bar, you don't have to do anything.






              share|improve this answer
























              • Where do I put this extension?

                – Callum
                Nov 25 '18 at 11:06











              • Anywhere you want :) You can put it below your entire view controller (not in the same class). If you want to be more organised and avoid a large file, you can put it in it's own file

                – Matt Le Fleur
                Nov 26 '18 at 12:15
















              0














              You can add an extension to UINavigationController:



              extension UINavigationController {
              open override var childForStatusBarStyle: UIViewController? {
              return visibleViewController
              }
              }


              Then for view controllers that you want a light status bar (white time, icons etc.), then override preferredStatusBarStyle:



              override var preferredStatusBarStyle: UIStatusBarStyle {
              return UIStatusBarStyle.lightContent
              }


              For a dark status bar, you don't have to do anything.






              share|improve this answer
























              • Where do I put this extension?

                – Callum
                Nov 25 '18 at 11:06











              • Anywhere you want :) You can put it below your entire view controller (not in the same class). If you want to be more organised and avoid a large file, you can put it in it's own file

                – Matt Le Fleur
                Nov 26 '18 at 12:15














              0












              0








              0







              You can add an extension to UINavigationController:



              extension UINavigationController {
              open override var childForStatusBarStyle: UIViewController? {
              return visibleViewController
              }
              }


              Then for view controllers that you want a light status bar (white time, icons etc.), then override preferredStatusBarStyle:



              override var preferredStatusBarStyle: UIStatusBarStyle {
              return UIStatusBarStyle.lightContent
              }


              For a dark status bar, you don't have to do anything.






              share|improve this answer













              You can add an extension to UINavigationController:



              extension UINavigationController {
              open override var childForStatusBarStyle: UIViewController? {
              return visibleViewController
              }
              }


              Then for view controllers that you want a light status bar (white time, icons etc.), then override preferredStatusBarStyle:



              override var preferredStatusBarStyle: UIStatusBarStyle {
              return UIStatusBarStyle.lightContent
              }


              For a dark status bar, you don't have to do anything.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 24 '18 at 12:32









              Matt Le FleurMatt Le Fleur

              1,6251833




              1,6251833













              • Where do I put this extension?

                – Callum
                Nov 25 '18 at 11:06











              • Anywhere you want :) You can put it below your entire view controller (not in the same class). If you want to be more organised and avoid a large file, you can put it in it's own file

                – Matt Le Fleur
                Nov 26 '18 at 12:15



















              • Where do I put this extension?

                – Callum
                Nov 25 '18 at 11:06











              • Anywhere you want :) You can put it below your entire view controller (not in the same class). If you want to be more organised and avoid a large file, you can put it in it's own file

                – Matt Le Fleur
                Nov 26 '18 at 12:15

















              Where do I put this extension?

              – Callum
              Nov 25 '18 at 11:06





              Where do I put this extension?

              – Callum
              Nov 25 '18 at 11:06













              Anywhere you want :) You can put it below your entire view controller (not in the same class). If you want to be more organised and avoid a large file, you can put it in it's own file

              – Matt Le Fleur
              Nov 26 '18 at 12:15





              Anywhere you want :) You can put it below your entire view controller (not in the same class). If you want to be more organised and avoid a large file, you can put it in it's own file

              – Matt Le Fleur
              Nov 26 '18 at 12:15











              0














              You may need to add "View controller-based status bar appearance" with a value of "YES" in your info.plist






              share|improve this answer




























                0














                You may need to add "View controller-based status bar appearance" with a value of "YES" in your info.plist






                share|improve this answer


























                  0












                  0








                  0







                  You may need to add "View controller-based status bar appearance" with a value of "YES" in your info.plist






                  share|improve this answer













                  You may need to add "View controller-based status bar appearance" with a value of "YES" in your info.plist







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 7 '18 at 7:09









                  Michael Ryan VillanuevaMichael Ryan Villanueva

                  293




                  293






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457475%2fattempting-to-change-the-uistatusbar-tint-color%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      TypeError: fit_transform() missing 1 required positional argument: 'X'