ios自訂狀態列顯示發送結果

來源:互聯網
上載者:User

標籤:ios 自訂狀態列

自訂狀態列,首先需要隱藏系統的statusbar然後重新顯示一個window即可

直接上代碼,可以直接使用:

//

//  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]"發送成功!";

        } 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]"發送失敗!";

     } completion:^(BOOL finished){

         self.frame=CGRectZero;

         self.hidden = YES;

     }];;

}

@end



ios自訂狀態列顯示發送結果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.