ios修改自用狀態列

來源:互聯網
上載者:User

標籤:

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES; //顯示  [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; //隱藏  [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; //顯示  [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; //隱藏 

讓狀態列顯示網路等待標誌 狀態列是可以通過UIApplication類提供的一些方法來修改的,比如完全去掉狀態列或者修改風格,不過這些改變只是在你的程式內部,當你退出你的程式又會複原。 ```objc UIApplication *myApp = [UIapplication sharedApplication];

1.隱藏狀態列 ```objc [myApp setStatusBarHidden:YES animated:YES];

記得隱藏狀態列後的你的“案頭”就增加320×20的大小,所以最好是在任何window或者view建立之前隱藏它。

2.狀態列風格 ```objc [myApp setStatusBarStyle: UIStatusbarStyleBlackOpaque];

typedef enum {          UIStatusBarStyleDefault,          UIStatusBarStyleBlackTranslucent,          UIStatusBarStyleBlackOpaque      } UIStatusBarStyle;

3.狀態列方向

[myApp setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];  typedef enum {       UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,       //豎屏,垂直向上       UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,       //豎屏,垂直方向上下顛倒       UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,       //裝置逆時針旋轉到橫屏模式       UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft       //裝置順時針旋轉到橫屏模式     } UIInterfaceOrientation; 

有時候,需要在狀態列上顯示一些自訂資訊,比如新浪微博的官方iOS用戶端:告知使用者資訊處於發送隊列、發送成功或者發送失敗。

如,通過在狀態列顯示自訂資訊,可以給方便使用又不影響軟體使用的提示。 為此,我們顯得定義一個自訂狀態列類,包含一個顯示資訊的Label:

@interface CustomStatusBar : UIWindow  {      UILabel *_messageLabel;  }   - (void)showStatusMessage:(NSString *)message;  - (void)hide;  @end  

接著,設定大小和系統狀態列一致,背景為黑色:

self.frame = [UIApplication sharedApplication].statusBarFrame;  self.backgroundColor = [UIColor blackColor];  

到這裡,為了讓自訂的狀態列可以讓使用者看到,還需要設定它的windowLevel。 在iOS中,windowLevel屬性決定了UIWindow的顯示層次。預設的windowLevel為UIWindowLevelNormal,即0.0。 系統定義了三個層次如下,具體可參考官方文檔:

const UIWindowLevel UIWindowLevelNormal;
const UIWindowLevel UIWindowLevelAlert;
const UIWindowLevel UIWindowLevelStatusBar;
typedef CGFloat UIWindowLevel;

為了能夠覆蓋系統預設的狀態列,我們把自訂的狀態列的windowLevel調高點: [cpp] view plaincopy self.windowLevel = UIWindowLevelStatusBar + 1.0f;

最後,為顯示資訊和隱藏添加一點無傷大雅的動畫:

- (void)showStatusMessage:(NSString *)message  {      self.hidden = NO;      self.alpha = 1.0f;      _messageLabel.text = @"";      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 };      } completion:^(BOOL finished){          _messageLabel.text = message;      }];  }  - (void)hide  {      self.alpha = 1.0f;      [UIView animateWithDuration:0.5f animations:^{          self.alpha = 0.0f;      } completion:^(BOOL finished){          _messageLabel.text = @"";          self.hidden = YES;      }];;  }  

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.