-1

I want to make status bar look solid black like Facebook(Blue) and should remain the same solid when navigation bar hides on scroll. I need to do it programmatically in swift. I don't want to add a UIView on the top. Can it be done with AppDelegate? I am not using navigation controller i am using Xibs.

Parth Adroja
  • 13,198
  • 5
  • 37
  • 71

1 Answers1

0

Yes you can easily create a UIView class and add it to app delegate like this:

    //In statusBar.h
    @interface statusBar : UIView{


    }


    //In statusBar.m

    @implementation statusBar

    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self)
        {


            self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];

            UIButton *navigationButton = [[UIButton alloc] initWitFrame:CGRectMake(10,10,25,25)];

[self addSubView:navigationButton];

        }
        return self;
    }

Now you can create its frame in app delegate like this:

//in appDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

 statusBar *sb = [[statusBar alloc] initWithFrame:CGRectMake(0,0, self.window.bounds.size.width, 50)];

[self.window addSubview:sb];

}

Now keep your frame of every view controller below the statusBar:

//In ViewDidLoad method:

 self.view.frame = CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height);  //50 is the height of status bar

Hope it will help.

Codobux
  • 1,028
  • 1
  • 12
  • 15