I want to change the Swift StatusBar color from the event.

Asked 2 years ago, Updated 2 years ago, 79 views

I understand that you can change the color of the status bar with the code below.

override var preferredStatusBarStyle:UIStatusBarStyle{
    return UISTatusBarStyle.lightContent
}

However, if I want to change the color when I press UIButton, what should I do?

I want to be able to change it with animation.

swift xcode swift4

2022-09-30 16:12

1 Answers

You can use this method to reflect style.

setNeedsStatusBarAppearanceUpdate()

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621354-setneedsstatusbarappearanceupdat

Indicators to the system that the view controller status bar attributes have changed.

Call this method if the view controller's status bar attributes, such as hidden/unhidden status or style, change.If you call this method with an animation block, the changes are animated along with the rest of the animation block.


2022-09-30 16:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.