你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> ios自定義狀態欄顯示發送結果

ios自定義狀態欄顯示發送結果

編輯:IOS開發綜合

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

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

//

// CustomStatusBar.h

// CustomStatusBar

//

// Created by yb on 14/10/24.

// Copyright (c) 2014年 yb. All rights reserved.

//


#import


@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



  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved