iOS 修改狀態列StatusBar的顏色及文字顏色

GabrielPanda發表於2018-01-24

設定背景色為黑色

-(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;  //文字白色
}  
複製程式碼

相關文章