码迷,mamicode.com
首页 > 移动开发 > 详细

ios自定义状态栏显示发送结果

时间:2014-11-05 17:18:53      阅读:197      评论:0      收藏:0      [点我收藏+]

标签: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;

        self.messageLabel.text=@"发送成功!";

        } 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;

         self.messageLabel.text=@"发送失败!";

     } completion:^(BOOL finished){

         self.frame=CGRectZero;

         self.hidden = YES;

     }];;

}

@end



ios自定义状态栏显示发送结果

标签:ios 自定义状态栏

原文地址:http://blog.csdn.net/yangbingbinga/article/details/40824285

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!