0

I want to change StatusBarStyle, am using preferredStatusBarStyle method and also added "View controller-based status bar appearance" is YES in plist, but i don't know, why is not working? I have mentioned following steps as below:

Step:1

// preferredStatusBarStyle Method

    -(UIStatusBarStyle)preferredStatusBarStyle
    {
        CGRect screenRect = [[UIScreen mainScreen] bounds];
        CGFloat SW = screenRect.size.width;
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

        UIView *statusView=[[UIView alloc]initWithFrame:CGRectMake(0, 0,SW,20)];
        statusView.backgroundColor=[UIColor blackColor];
        [self.view addSubview:statusView];
        return UIStatusBarStyleLightContent;
    }

Step:2

//Add plist

View controller-based status bar appearance="YES"

Step:3

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self preferredStatusBarStyle];
 }

Please suggest me.

Prashant
  • 41
  • 9

1 Answers1

0

There is no direct way of changing the Status Bar color. We can just choose the status bar style using the “setStatusBarStyle” property and choose among the three available styles which are –

UIStatusBarStyleDefault
UIStatusBarStyleBlackTranslucent
UIStatusBarStyleBlackOpaque

However if you would like to change the color of status bar, there is a trick which can do the same –

Change the background color of your UIWindow object. And set the status bar style to “UIStatusBarStyleBlackTranslucent”. This will set the color of status bar same as the background color of the window.

Add the following code to your AppDeligate.m file in the applicationDidFinishLaunchingWithOptions –

self.window.backgroundColor = [UIColor colorWithRed:0.78f green:0.13f blue:0.11f alpha:1];
[application setStatusBarStyle:UIStatusBarStyleBlackTranslucent];

Or check below tutorial for customize your Status bar appcoda

9to5ios
  • 5,319
  • 2
  • 37
  • 65