user3607973
user3607973

Reputation: 345

Dynamically change status bar text color

I know I can change the iPhone's status bar text color, using methods described here.

However, my app has different themes, and I need to update the status bar accordingly.

Calling

[self setNeedsStatusBarAppearanceUpdate];

and

-(UIStatusBarStyle)preferredStatusBarStyle{ 
    return UIStatusBarStyleLightContent; 
}

will obviously not work. However, it needs to be local, as in only for a specific TabBar view.

Upvotes: 0

Views: 1841

Answers (2)

WajahatAliKhan
WajahatAliKhan

Reputation: 9

Just for the ones who come here for the title. You can set a flag and toggle between the status bar text colors like in the code segment given:

-(UIStatusBarStyle)preferredStatusBarStyle {

if (barStyleLight){

    return UIStatusBarStyleLightContent;
}
else {

    return UIStatusBarStyleDefault;
}

}

Also note that, this preferredStatusBarStyle method is called whenever we call: [self setNeedsStatusBarAppearanceUpdate];

Hope it helps.

Upvotes: 0

ikarishinjigao
ikarishinjigao

Reputation: 129

First, select your Project and in the Genernal tab you will see something like this.

enter image description here

Then set Status Bar Style to Light just like the image.

Second, set View controller-based status bar appearance equal to NO in Info.plist. If you can't find it, just add a new row and set it like the above step.

And then, run your app you will see the Status bar text colour is white. :)

Upvotes: 1

Related Questions