3

I am trying to add a view on top of the statusbar. I have been following this SO post: Adding view on StatusBar in iPhone

For some reason, when I create the window and set Hidden to NO, the view does not appear to show up on top of the statusbar. Does this implementation still work in ios5.1?

Thanks!

This is my custom UIWindow class:

@implementation StatusBarOverlay

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    // Place the window on the correct level and position
    self.hidden = NO;
    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:@"bar_0.png"];
    backgroundImageView.animationImages = [NSArray arrayWithObjects:[UIImage     imageNamed:@"bar_1.png"],
                                           [UIImage imageNamed:@"bar_2.png"],
                                           [UIImage imageNamed:@"bar_3.png"],
                                           nil];
    backgroundImageView.animationDuration = 0.8;
    [backgroundImageView startAnimating];
    [self addSubview:backgroundImageView];
}
return self;
}

In my viewcontroller, I created the new window and called this in viewDidLoad:

StatusBarOverlay *overlayWindow = [[StatusBarOverlay alloc] initWithFrame:CGRectZero];
[overlayWindow makeKeyAndVisible];

However, the view still doesn't show up. Any idea as to why?

Screenshot showing error using private api

Community
  • 1
  • 1
chourobin
  • 4,004
  • 4
  • 35
  • 48
  • the post you refer to says right at the top that the app got rejected by the apple store because it tried to do this. is there a reason you can't just hide the status bar, and then create a subview that looks like the statusbar that can be embedded in the view that now has a hidden status bar? – john.k.doe Jun 26 '12 at 22:32
  • Apple wouldn't allow this in a thousand years. You're app would get rejected faster than a taco from Taco Bell travels through your bowels. – jakenberg Jan 26 '13 at 10:44

3 Answers3

4

set your application's window level to UIWindowLevelStatusBar:

self.window.windowLevel = UIWindowLevelStatusBar;

and then add your own view to application window anywhere:

[[[UIApplication sharedApplication]delegate].window addSubview:yourview];

this problem came to me recently, and I just solved it through this way

ouyang
  • 41
  • 2
0

You can create a new UIWindow and add your view to that. Set the windows frame to [[UIApplication sharedApplication] statusBarFrame] and call makeKeyAndVisible to make it visible.

Benedict Cohen
  • 11,912
  • 7
  • 55
  • 67
  • I tried calling makeKeyAndVisible but still no luck. I updated my question with my code sample. Thanks for trying! – chourobin Jun 14 '12 at 11:49
0

In the end, I subclassed UIWindow and made that the primary UIWindow in the application AppDelegate. I added any custom view and set the window level to UIWindowLevelStatusBar to display on top of the status bar.

chourobin
  • 4,004
  • 4
  • 35
  • 48