iOS Custom status bar displays send results

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.