状态栏显示进度加载

子类化UIWindow,在状态栏上创建UIProgressView加载进度条,创建UILabel显示文字

//StatusBarWindow.h

@interface StatusBarWindow : UIWindow

{

    UIProgressView *_progressView;

    UILabel *_sendLabel;

}

//显示状态栏进度加载

- (void)showProgressView:(NSString *)text show:(BOOL)show operation:(AFHTTPRequestOperation *)operation;

//隐藏

- (void)hidden;


#import "StatusBarWindow.h"

#import "UIProgressView+AFNetworking.h"

@implementation StatusBarWindow

- (instancetype)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        //设置window的优先级

        self.windowLevel = UIWindowLevelStatusBar;

        //置背景颜色

        self.backgroundColor = [UIColor blackColor];

    }

    return self;

}

//显示状态栏进度加载

- (void)showProgressView:(NSString *)text show:(BOOL)show operation:(AFHTTPRequestOperation *)operation

{

    

    //创建加载进度条

    //做安全判断,如果已经创建,则不再重复创建

    if (_progressView == nil) {

        _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 15, kScreenWidth, 5)];

    }

    [self addSubview:_progressView];

    

    //创建sendLabel显示文字,正在加载,加载成功

    //做安全判断,如果已经创建,则不再重复创建

    if (_sendLabel == nil) {

        _sendLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 15)];

        //字体大小

        _sendLabel.font = [UIFont systemFontOfSize:11];

        _sendLabel.backgroundColor = [UIColor clearColor];

        //居中对齐

        _sendLabel.textAlignment = NSTextAlignmentCenter;

        //设置字体颜色

        _sendLabel.textColor = [UIColor whiteColor];

    }

    [self addSubview:_sendLabel];

    

    _sendLabel.text = text;

    //window设置为不隐藏

    self.hidden = NO;

    

    if(show) {

        //显示window

        //使用第三方框架AFNetworking中的"UIProgressView+AFNetworking"文件实现上传进度显示

        [_progressView setProgressWithUploadProgressOfOperation:operation animated:YES];

        

    }else {

        //延迟2秒,隐藏window

        [self performSelector:@selector(hidden) withObject:nil afterDelay:2];

    }

}

//隐藏

- (void)hidden

{

    self.hidden = YES;

}

@end


在调用这个方法时,

- (void)showProgressView:(NSString *)text show:(BOOL)show operation:(AFHTTPRequestOperation *)operation;

先创建StatusBarWindow,

然后

[statusWindow showProgressView:@"正在发送" show:YES operation:operation];






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值