自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

自定義iOS狀態(tài)欄

移動開發(fā) iOS
為了讓自定義的狀態(tài)欄可以讓用戶看到,設置了它的windowlevel,在ios中,windowlevel屬性決定了UIWindow的顯示層次,默認的windowlevel為UIWindowLevelNormal,即0.0 。為了能覆蓋默認的狀態(tài)欄,將windowlevel設置高點。其他代碼基本上都不解釋什么,如果要特殊效果,可以自己添加。

如果需要在狀態(tài)欄顯示自定義的消息時,就需要自定義狀態(tài)欄。

代碼如下:

XYCustomStatusBar.h

  1. #import <UIKit/UIKit.h>   
  2. @interface XYCustomStatusBar : UIWindow{   
  3.      UILabel *_messageLabel;   
  4.  }   
  5.  - (void)showStatusMessage:(NSString *)message;   
  6. - (void)hide;   
  7. @end  

XYCustomStatusBar.m

  1. #import "XYCustomStatusBar.h"   
  2.  @implementation XYCustomStatusBar       
  3.  - (void)dealloc{   
  4.     [super dealloc];   
  5.     [_messageLabel release], _messageLabel = nil;   
  6.  }       
  7.  - (id)init{   
  8.      self = [super init];   
  9.      if (self) {   
  10.          self.frame = [UIApplication sharedApplication].statusBarFrame;   
  11.          self.backgroundColor = [UIColor blackColor];   
  12.          self.windowLevel = UIWindowLevelStatusBar + 1.0f;   
  13.          _messageLabel = [[UILabel alloc] initWithFrame:self.bounds];   
  14.          [_messageLabel setTextColor:[UIColor whiteColor]];   
  15.          [_messageLabel setTextAlignment:NSTextAlignmentRight];   
  16.          [_messageLabel setBackgroundColor:[UIColor clearColor]];   
  17.          [self addSubview:_messageLabel];   
  18.      }   
  19.      return self;   
  20.  }   
  21.  - (void)showStatusMessage:(NSString *)message{   
  22.      self.hidden = NO;   
  23.      self.alpha = 1.0f;   
  24.      _messageLabel.text = @"";   
  25.      CGSize totalSize = self.frame.size;   
  26.      self.frame = (CGRect){ self.frame.origin, 0, totalSize.height };   
  27.      [UIView animateWithDuration:0.5 animations:^{   
  28.          self.frame = (CGRect){self.frame.origin, totalSize };   
  29.      } completion:^(BOOL finished){   
  30.          _messageLabel.text = message;   
  31.      }];   
  32.  }   
  33.  - (void)hide{   
  34.      self.alpha = 1.0f;           
  35.      [UIView animateWithDuration:0.5f animations:^{   
  36.          self.alpha = 0.0f;   
  37.      } completion:^(BOOL finished){   
  38.          _messageLabel.text = @"";   
  39.          self.hidden = YES;   
  40.      }];   
  41.  }   
  42.  @end  

為了讓自定義的狀態(tài)欄可以讓用戶看到,設置了它的windowlevel,在ios中,windowlevel屬性決定了UIWindow的顯示層次,默認的windowlevel為UIWindowLevelNormal,即0.0 。為了能覆蓋默認的狀態(tài)欄,將windowlevel設置高點。其他代碼基本上都不解釋什么,如果要特殊效果,可以自己添加。

責任編輯:閆佳明 來源: oschina
相關推薦

2012-12-24 14:42:48

iOS自定義狀態(tài)欄

2014-06-06 14:03:13

iOS狀態(tài)欄提示控件原理

2021-08-24 15:25:59

鴻蒙HarmonyOS應用

2013-11-20 15:08:32

iOS開發(fā)狀態(tài)欄

2013-06-27 11:10:01

iOS開發(fā)自定義UISlider

2017-02-17 11:00:57

狀態(tài)欄Android

2012-06-01 11:02:33

2017-10-25 14:07:54

APPiOSxcode

2013-05-30 15:53:17

iOS開發(fā)iOS SDKPopver

2021-01-20 08:58:39

iOS 14桌面圖標快捷指令

2011-08-02 11:17:13

iOS開發(fā) View

2015-02-12 14:49:36

CGToast狀態(tài)欄提示Status

2016-11-29 11:20:08

Android

2011-05-04 10:40:02

網頁加載進度標題欄lephone

2015-02-12 15:33:43

微信SDK

2015-01-15 16:45:05

iOS源碼自定義畫圖

2022-07-15 16:39:46

ETS導航欄組件

2017-02-08 20:21:03

Windows 10Windows任務欄

2015-02-12 15:38:26

微信SDK

2016-04-06 11:14:48

iOS相機自定義
點贊
收藏

51CTO技術棧公眾號