Thursday 2 January 2014

Show text on status bar

-(void)showStatusBarMessage:(NSString *)message hideAfter:(NSTimeInterval)delay
{
    __block UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:[UIApplication sharedApplication].statusBarFrame];
    statusWindow.windowLevel = UIWindowLevelStatusBar + 1;
    UILabel *label = [[UILabel alloc] initWithFrame:statusWindow.bounds];
    label.textAlignment = UITextAlignmentCenter;
    label.backgroundColor = [UIColor blackColor];
    label.textColor = [UIColor grayColor];
    label.font = [UIFont boldSystemFontOfSize:13];
    label.text = message;
    [statusWindow addSubview:label];
    [statusWindow makeKeyAndVisible];
    label.layer.transform = CATransform3DMakeRotation(M_PI * 0.5, 1, 0, 0);
    [UIView animateWithDuration:0.7 animations:^{
        label.layer.transform = CATransform3DIdentity;
    }completion:^(BOOL finished){
        double delayInSeconds = delay;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [UIView animateWithDuration:0.5 animations:^{
                label.layer.transform = CATransform3DMakeRotation(M_PI * 0.5, -1, 0, 0);
            }completion:^(BOOL finished){
                statusWindow = nil;
                [[[UIApplication sharedApplication].delegate window] makeKeyAndVisible];
            }];
        });
    }];
}

No comments:

Post a Comment