Adding View to StatusBar on iPhone

Can I add a UIView to a staus bar of size (320 x 20)? I do not want to hide the status bar, I only want to add it on top of the status bar.

+61
iphone uikit uiapplication
May 14 '10 at 11:24
source share
5 answers

You can easily accomplish this by creating your own window above the existing status bar.

Just create a simple subclass of UIWindow with the following override of initWithFrame:

 @interface ACStatusBarOverlayWindow : UIWindow { } @end @implementation ACStatusBarOverlayWindow - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { // Place the window on the correct level and position self.windowLevel = UIWindowLevelStatusBar+1.0f; self.frame = [[UIApplication sharedApplication] statusBarFrame]; // Create an image view with an image to make it look like a status bar. UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.frame]; backgroundImageView.image = [UIImage imageNamed:@"statusBarBackground.png"]; [self addSubview:backgroundImageView]; [backgroundImageView release]; // TODO: Insert subviews (labels, imageViews, etc...) } return self; } @end 

Now you can, for example, in the view controller in your application create an instance of your new class and make it visible.

 overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero]; overlayWindow.hidden = NO; 

Remember that you are using window status with - (void)makeKeyAndVisible or similar. If you make your main window ( UIWindow in application deletion) a free key status, you will encounter problems scrolling scrollviews from the top when you click on the status bar, etc.

+85
May 14 '10 at 12:22
source share

I wrote a static library overlaying the Reeders status bar, you can find it here: https://github.com/myell0w/MTStatusBarOverlay

MTStatusBarOverlayMTStatusBarOverlay

It currently supports iPhone and iPad, default style styles and opaque black statuses, rotation, 3 different anymation modes, history tracking and many other useful features!

Feel free to use it or send me a Pull request to improve it!

+58
Dec 10 '10 at 23:51
source share

All answers look like working, but in iOS6.0 I have the following problems:

1 / Spins look bad

2 / Window (status bar is a window view) required by rootViewController

I am using the answer from myell0w , but the rotation does not work very well. I simply remove one additional window and use the UIWindow from AppDelegate to create the status bar. Maybe this solution is approved for only one UIViewController application ...

Ive implemented as follows:

1 / In ApplicationDelegate:

 self.window.windowLevel = UIWindowLevelStatusBar + 1; self.window.backgroundColor = [UIColor clearColor]; self.window.rootViewController = _journalController; 

2 / Create a custom UIView and implement everything you need: As an example, you can see the status bar:

 @interface LoadingStatusBar : UIControl 

And easily create and add to the controller view:

 _loadingBar = [[LoadingStatusBar alloc] initWithFrame:topFrame]; [self addSubview:_loadingBar]; 

3 / Magic when adding a controller view (in initWithFrame :)

  CGRect mainFrame = self.bounds; mainFrame.origin.y = 20; self.bounds = mainFrame; 

In your view of the controller there will be 2 types - viewing the contents and displaying the status bar. You can show the status bar or hide it whenever you want. The content viewing frame will be:

 _contentView.frame = CGRectMake(0, 20, self.bounds.size.width, self.bounds.size.height); 

4 / And one last magic here :) To detect touches in an insensitive area, I used:

 -(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event { if (point.y < 20) return _loadingBar; return [super hitTest:point withEvent:event]; } 

At the moment, it works great on the iPad / iPhone and all iOS from 4 to 6.

+4
Nov 20 '12 at 14:40
source share

Just to reject "You cannot make this comments" ...

I do not know how, but I know that this is doable. A Reader Reader application called Reeder does this.

As you can see in the screenshot, Reeder places a small dot in the upper right corner of the screen. When you click it. The bar will fill the entire status bar until you click it again to make it small.

A small icon on the top right of the screenalt text

+3
May 14 '10 at 11:58 a.m.
source share

First of all, many thanks to @Martin Allรฉus for providing the code for this implementation.

I am just sending a message about the problem that I am facing, and about which solution I used, because, as I believe, others may encounter the same problem.

If the application is launched during a call, the height of the status bar will be 40 pixels, and this means that the custom status bar will be initialized to this height. But if the call is completed while you are still in the application, the height of the status bar will remain at 40 pixels, and it will look strange.

So the solution is simple: I used the Notification Center to subscribe to the frame change delegate in the application status bar and configure the frame:

 - (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame { //an in call toggle was done //fire notification [[NSNotificationCenter defaultCenter] postNotificationName:kStatusBarChangedNotification object:[NSValue valueWithCGRect:oldStatusBarFrame]]; } 

And at ACStatusBarOverlayWindow we subscribe to the notification:

 -(id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { // Place the window on the correct level & position self.windowLevel = UIWindowLevelStatusBar + 1.0f; self.frame = [UIApplication sharedApplication].statusBarFrame; self.backgroundColor = [UIColor blackColor]; //add notification observer for in call status bar toggling [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarChanged:) name:kStatusBarChangedNotification object:nil]; } return self; } 

and our code for setting the frame:

 - (void)statusBarChanged:(NSNotification*)notification { //adjust frame... self.frame = [UIApplication sharedApplication].statusBarFrame; //you should adjust also the other controls you added here } 

kStatusBarChangedNotification is just a constant that I used for a simple reference, you can just replace it with a string or declare a constant globally.

+1
Oct 23
source share



All Articles