ios - How to update the status bar style when transitioning to a new view controller? -


i have container view controller transitions 1 child view controller child using code:

- (void)switchtonewviewcontroller:(uiviewcontroller *)newcontroller {   [self      transitionfromviewcontroller:self.currentviewcontroller      toviewcontroller:newcontroller     duration: 0.6     options:uiviewanimationoptiontransitionflipfromleft     animations:^{       newcontroller.view.frame = self.currentviewcontroller.view.frame;     }     completion:^(bool finished) {       [self.currentviewcontroller removefromparentviewcontroller];       [newcontroller didmovetoparentviewcontroller:self];       self.currentviewcontroller = newcontroller;     }   ]; }  - (uiviewcontroller*)childviewcontrollerforstatusbarstyle {   return self.currentviewcontroller; } 

i have problem when first view controller prefers dark text in status bar next view controller prefers light text.

first view controller:

- (uistatusbarstyle)preferredstatusbarstyle {     return uistatusbarstyledefault; } 

second view controller:

- (uistatusbarstyle)preferredstatusbarstyle {     return uistatusbarstylelightcontent; } 

i put breakpoint in both first , second view controller's preferredstatusbarstyle. debugger breaks on first view controller, not on second view controller. result, status bar style doesn't change. how notify cocoa framework needs read second view controller's preference?

ensure uiviewcontrollerbasedstatusbarappearance set yes in info.plist file. should ensure preferredstatusbarstyle called per view controller.

failing that, set above plist key no, add following viewwillappear in each of uiviewcontroller's implementation files:

if ([self respondstoselector:@selector(setneedsstatusbarappearanceupdate)]) { [self setneedsstatusbarappearanceupdate]; }

you need ensure implemented in every view controller in need update appearance of status bar.

if else fails

call following wherever want update status bar style:

[[uiapplication sharedapplication] setstatusbarstyle:uistatusbarstylelightcontent];

obviously replacing style desired status bar style.

hope helps!