snail-z/zhPopupController

你好,弹出的时候怎么改变状态栏的颜色?

ganjmeng opened this issue · 2 comments

你好,弹出的时候怎么改变状态栏的颜色?
我设置了
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
}
没有效果,求解

    __weak typeof(self) w_self = self;
    self.sl_popupController.willPresent = ^(SnailPopupController * _Nonnull popupController) {
        [w_self sl_setStatusBarStyle:UIStatusBarStyleLightContent];
    };
    
    self.sl_popupController.didDismiss = ^(SnailPopupController * _Nonnull popupController) {
        [w_self sl_setStatusBarStyle:UIStatusBarStyleDefault];
    };
#import "UIViewController+StatusBar.h"
#import <objc/runtime.h>

@implementation UINavigationController (StatusBarStyle)

- (UIViewController *)childViewControllerForStatusBarStyle {
    return self.topViewController;
}

- (UIViewController *)childViewControllerForStatusBarHidden {
    return self.topViewController;
}

@end

static void *sl_UIViewControllerStatusBarStyleKey = &sl_UIViewControllerStatusBarStyleKey;
static void *sl_UIViewControllerStatusBarHiddenKey = &sl_UIViewControllerStatusBarHiddenKey;

@implementation UIViewController (StatusBar)

- (void)setIsLightContent:(BOOL)isLightContent {
    objc_setAssociatedObject(self, sl_UIViewControllerStatusBarStyleKey, @(isLightContent), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (BOOL)isLightContent {
    id value = objc_getAssociatedObject(self, sl_UIViewControllerStatusBarStyleKey);
    return [(NSNumber *)value boolValue];
}

- (void)setIsHidden:(BOOL)isHidden {
    objc_setAssociatedObject(self, sl_UIViewControllerStatusBarHiddenKey, @(isHidden), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (BOOL)isHidden {
    id value = objc_getAssociatedObject(self, sl_UIViewControllerStatusBarHiddenKey);
    return [(NSNumber *)value boolValue];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    if (self.isLightContent) {
        return UIStatusBarStyleLightContent;
    }
    return UIStatusBarStyleDefault;
}

- (BOOL)prefersStatusBarHidden {
    return self.isHidden;
}

- (void)sl_setStatusBarStyle:(UIStatusBarStyle)statusBarStyle {
    self.isLightContent = statusBarStyle == UIStatusBarStyleLightContent;
    [self setNeedsStatusBarAppearanceUpdate];
}

- (void)sl_setStatusBarHidden:(BOOL)statusBarHidden {
    self.isHidden = statusBarHidden;
    [self setNeedsStatusBarAppearanceUpdate];
}

- (void)sl_resetStatusBarStyle {
    self.isLightContent = NO;
    self.isHidden = NO;
    [self setNeedsStatusBarAppearanceUpdate];
}

@end
#import <UIKit/UIKit.h>

@interface UIViewController (StatusBar)

- (void)sl_setStatusBarHidden:(BOOL)statusBarHidden;
- (void)sl_setStatusBarStyle:(UIStatusBarStyle)statusBarStyle;
- (void)sl_resetStatusBarStyle;

@end

多谢大神