Search code examples
iosstatusbar

Change status bar alpha


In the Snapchat app, the status bar changes alpha when a table view is dragged down to reload.

This is the normal status bar This is the normal status bar

This is what happens when the table view is dragged down enter image description here

How is the status bar alpha changed? And how is the frame changed? Originally I thought it was a snapshot, but the clock changes as it normally should.


Solution

  • This should do the trick for the fade animation:

    /* Swift 3 */
    
    let statusBarWindow = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow
    UIView.animate(withDuration: 2) {
        statusBarWindow?.alpha = 0.2
    }
    
    /* Objective-C */
    
    UIWindow *statusBarWindow = (UIWindow *)[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
    [UIView animateWithDuration:2.f 
                     animations:^{ [statusBarWindow setAlpha:0.2]; } 
                     completion:nil];
    

    You can also set statusBarWindow's frame and move it how you want. Have fun ;]