iOS modify your own status bar

Source: Internet
Author: User

[UIApplication sharedapplication].networkactivityindicatorvisible = YES; Display  [uiapplication sharedapplication].networkactivityindicatorvisible = NO;//Hide  [uiapplication sharedapplication].networkactivityindicatorvisible = YES; Show  

Let the status bar display the network wait Flag status bar is available through the UIApplication class provides some methods to modify, such as completely remove the status bar or modify style, but these changes are only within your program, when you quit your program will be restored. "' OBJC uiapplication *myapp = [UIApplication sharedapplication];

1. Hide the status bar "' OBJC [myApp setstatusbarhidden:yes Animated:yes];

Remember to hide the status bar after your "desktop" increases the size of the 320x20, so it is best to hide it before any window or view creation.

2. Status bar Style ' ' OBJC [myApp setstatusbarstyle:uistatusbarstyleblackopaque];

typedef enum {          UIStatusBarStyleDefault,          UIStatusBarStyleBlackTranslucent,          UIStatusBarStyleBlackOpaque      } UIStatusBarStyle;

3. Status bar Direction

[MyApp setstatusbarorientation:uiinterfaceorientationlandscapeleft Animated:no];  typedef enum {       uiinterfaceorientationportrait           = uideviceorientationportrait,       //Vertical screen, vertical up       Uiinterfaceorientationportraitupsidedown = Uideviceorientationportraitupsidedown,       //Vertical screen, upside       down vertically Uiinterfaceorientationlandscapeleft      = uideviceorientationlandscaperight,       //device is rotated counterclockwise to horizontal screen mode       Uiinterfaceorientationlandscaperight     = uideviceorientationlandscapeleft       //device rotates clockwise to horizontal screen mode     

Sometimes it is necessary to display some custom information on the status bar, such as the official iOS client of Sina Weibo: informing the user that the message is in the sending queue, sending it successfully, or failing to send it.

For example, by displaying custom information in the status bar, you can be user-friendly without compromising the software's use of hints. To do this, we appear to define a custom status bar class that contains a label that displays information:

@interface Customstatusbar:uiwindow  {      UILabel *_messagelabel;  }   -(void) Showstatusmessage: (NSString *) message;  -(void) hide;  @end  

Next, set the size to match the system status bar and the background is black:

Self.frame = [UIApplication sharedapplication].statusbarframe;  Self.backgroundcolor = [Uicolor blackcolor];  

Here, in order for the custom status bar to be visible to the user, it is also necessary to set its windowlevel. In iOS, the Windowlevel property determines the level of display for UIWindow. The default windowlevel is Uiwindowlevelnormal, which is 0.0. The system defines three levels as follows, with reference to the official documentation:

Const Uiwindowlevel Uiwindowlevelnormal;
Const Uiwindowlevel Uiwindowlevelalert;
Const Uiwindowlevel Uiwindowlevelstatusbar;
typedef cgfloat Uiwindowlevel;

To be able to override the system's default status bar, we windowlevel the custom status bar: [CPP] View plaincopy self.windowlevel = Uiwindowlevelstatusbar + 1.0f;

Finally, add a little harmless animation for displaying information and hiding:

-(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 modify your own status bar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.