I want to change the Status Bar color with the specific view controller.
According to StackOverFlow's answers , i achieved it.
There is an issue , when switching apps on iPhone, the color I have set fades, goes back to initial state.
It's OK. Please notice the status bar.
Not OK. Please notice the status bar.
I can't figure it out. The code I tried:
set statusBar.backgroundColor
,
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = [UIColor redColor ];
}
2. insert subview to statusBar.
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
UIView * backgroundColorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 20) ];
backgroundColorView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
backgroundColorView.backgroundColor = [UIColor redColor ];
[statusBar.subviews.firstObject insertSubview: backgroundColorView atIndex:0];
3. So is to insert layer(CALayer).
And I tried to analyze it with breakpoints.
- When the app is a active, and double-click the Home button to Switch apps, the method is not called - (void)viewWillDisappear:(BOOL)animated
. It confuses me a little .
- I try to change the background color of status bar in the Application's method - (void)applicationWillResignActive:(UIApplication *)application
, It doesn't work. I don't know why.
While from Github's source code, It's OK through Runtime. My company don't like using Runtime.
Is there some other way without runtime ?
And I don't know how runtime interacts with iPhone's switching apps mode.
The main question is to solve it without runtime. More explain is welcomed. i think it is easy , what do i miss ?
Many thanks in advances.
See Question&Answers more detail:
os