iOS-修改状态栏StatusBar的颜色及文字颜色

设置背景色为黑色

-(void)setUpStatusBarView
{
    if (!self.statusBarView)
    {
        CGFloat x,y,w,h;
        x = 0;
        y = 0;
        w = self.view.frame.size.width;
        h = 0;
        CGRect rect_start = (CGRect){x,y,w,h};
        
        self.statusBarView = [[UIImageView alloc] initWithFrame:rect_start];
        
        if ([[UIDevice currentDevice] systemVersion].floatValue>=7.0)
        {
            x = self.statusBarView.frame.origin.x;
            y = self.statusBarView.frame.origin.y;
            w = self.statusBarView.frame.size.width;
            h =//状态栏高度;
            CGRect rect_new = (CGRect){x,y,w,h};
            
            self.statusBarView.frame = rect_new;
            
            self.statusBarView.backgroundColor = [UIColor clearColor];
            ((UIImageView *)self.statusBarView).backgroundColor =  [UIColor blackColor];//设置为黑色
            [self.view addSubview:self.statusBarView];
        }
    }
    
}

- (UIStatusBarStyle)preferredStatusBarStyle
{  
    return UIStatusBarStyleLightContent;  //文字白色
}  

你可能感兴趣的:(iOS-修改状态栏StatusBar的颜色及文字颜色)