To customize the status bar, you first need to hide the system's StatusBar and then display a window again
Directly on the code, you can directly use:
//
CustomStatusBar.h
Customstatusbar
//
Created by YB on 14/10/24.
Copyright (c) 2014 YB. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface Customstatusbar:uiwindow
-(void) Showstatusmessage: (NSString *) message;
-(void) hidestatusbarwhensendfinished;
-(void) hidestatusbarwhensendfailed;
@end
//
Customstatusbar.m
Customstatusbar
//
Created by YB on 14/10/24.
Copyright (c) 2014 YB. All rights reserved.
//
#import "CustomStatusBar.h"
@interface Customstatusbar ()
@property (strong,nonatomic) UILabel *messagelabel;
@end
@implementation Customstatusbar
-(Instancetype) init
{
self = [super init];
if (self) {
Self.frame=[uiapplication Sharedapplication].statusbarframe;
Self.backgroundcolor=[uicolor Blackcolor];
self.windowlevel=uiwindowlevelstatusbar+1.0f;
Self.messagelabel=[[uilabel Alloc]initwithframe:self.bounds];
Self.messagelabel.textcolor=[uicolor Whitecolor];
Self.messagelabel.textalignment=nstextalignmentcenter;
[Self Addsubview:_messagelabel];
}
return self;
}
-(void) Showstatusmessage: (NSString *) message
{
Self.hidden = NO;
Self.alpha = 1.0f;
Self.frame=[uiapplication Sharedapplication].statusbarframe;
Self.messagelabel.frame=self.bounds;
Cgsize totalsize = self.frame.size;
Self.frame = (cgrect) {self.frame.origin, 0, totalsize.height};
[UIView animatewithduration:0.5f animations:^{
Self.frame = (cgrect) {self.frame.origin, totalsize};
Self.messageLabel.text = message;
} completion:^ (BOOL finished)
{
}];
}
-(void) hidestatusbarwhensendfinished
{
Self.alpha = 1.0f;
[UIView animatewithduration:2.0f animations:^
{
Self.alpha = 0.0f;
CGRect Frame=self.frame;
frame.size.height=0;
Self.frame=frame;
[email protected] "sent successfully!";
} completion:^ (BOOL finished) {
Self.frame=cgrectzero;
Self.hidden = YES;
}];;
}
-(void) hidestatusbarwhensendfailed
{
Self.alpha = 1.0f;
[UIView animatewithduration:2.0f animations:^
{
Self.alpha = 0.0f;
CGRect Frame=self.frame;
frame.size.height=0;
Self.frame=frame;
[Email protected] "Send failed!";
} completion:^ (BOOL finished) {
Self.frame=cgrectzero;
Self.hidden = YES;
}];;
}
@end
iOS Custom status bar displays send results