Attempting to Change the UIStatusBar Tint Color
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
add a comment |
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
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 aUINavigationController
scenario. SO far, the OP has only said "in a specific VC". TO the OP, could you provide more specifics? I've successfully overridenpreferredStatusBarStyle
many time. It doesn't need a call tosetNeedsStatusBarAppearanceUpdate
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
add a comment |
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
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
swift uistatusbar
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 aUINavigationController
scenario. SO far, the OP has only said "in a specific VC". TO the OP, could you provide more specifics? I've successfully overridenpreferredStatusBarStyle
many time. It doesn't need a call tosetNeedsStatusBarAppearanceUpdate
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
add a comment |
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 aUINavigationController
scenario. SO far, the OP has only said "in a specific VC". TO the OP, could you provide more specifics? I've successfully overridenpreferredStatusBarStyle
many time. It doesn't need a call tosetNeedsStatusBarAppearanceUpdate
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
add a comment |
3 Answers
3
active
oldest
votes
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
}
}
add a comment |
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.
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
add a comment |
You may need to add "View controller-based status bar appearance" with a value of "YES" in your info.plist
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
}
}
add a comment |
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
}
}
add a comment |
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
}
}
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
}
}
answered Nov 24 '18 at 12:28
AmmarAmmar
1929
1929
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
You may need to add "View controller-based status bar appearance" with a value of "YES" in your info.plist
add a comment |
You may need to add "View controller-based status bar appearance" with a value of "YES" in your info.plist
add a comment |
You may need to add "View controller-based status bar appearance" with a value of "YES" in your info.plist
You may need to add "View controller-based status bar appearance" with a value of "YES" in your info.plist
answered Dec 7 '18 at 7:09
Michael Ryan VillanuevaMichael Ryan Villanueva
293
293
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 overridenpreferredStatusBarStyle
many time. It doesn't need a call tosetNeedsStatusBarAppearanceUpdate
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