Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios5.1 adding a UIView on top of iphone statusbar

Tags:

uikit

iphone

ios5

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

like image 257
chourobin Avatar asked Dec 29 '25 00:12

chourobin


1 Answers

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

like image 51
ouyang Avatar answered Dec 31 '25 14:12

ouyang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!