[CPP]View Plain copy print?
- [UIApplication sharedapplication].networkactivityindicatorvisible = YES; Show
- [UIApplication sharedapplication].networkactivityindicatorvisible = NO; Hide
Let the status bar display the network wait flag
The status bar can be modified by some of the methods provided by the UIApplication class, such as completely removing the status bar or modifying the style, but these changes are only within your program and will be restored when you exit your program.
- UIApplication *myapp = [UIApplication sharedapplication];
Copy Code
1. Hide the status bar
- [MyApp Setstatusbarhidden:yes Animated:yes];
Copy Code
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
- [MyApp Setstatusbarstyle:uistatusbarstyleblackopaque];
Copy Code
- typedef enum {
- Uistatusbarstyledefault,
- Uistatusbarstyleblacktranslucent,
- Uistatusbarstyleblackopaque
- } Uistatusbarstyle;
Copy code 3. Status Bar Direction
- [MyApp Setstatusbarorientation:uiinterfaceorientationlandscapeleft Animated:no];
Copy Code
- typedef enum {
- UIInterfaceOrientationPortrait &nbs p; = uideviceorientationportrait,
- //vertical screen, vertical upward
- uiinterfaceorientationportraitupsidedown = UIDEVICEORIENTATIONPORTRAITUPSIDEDOWN, &NBSP
- //vertical screen, vertically upside down &NBSP
- UIInterfaceOrientationLandscapeLeft = UIDEVICEORIENTATIONLANDSCAPERIGHT, &NBSP
- //device rotate counterclockwise to horizontal screen mode
- UIInterfaceOrientationLandscapeRight = UIDEVICEORIENTATIONLANDSCAPELEFT &NBSP
- //device rotate clockwise to landscape mode
- } uiinterfaceorientation;
Copy Code
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:
[CPP]View Plain Copy
- @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:
[CPP]View Plain Copy
- 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:
[CPP]View Plain Copy
- 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 Plain Copy
- Self.windowlevel = Uiwindowlevelstatusbar + 1.0f;
Finally, add a little harmless animation for displaying information and hiding:
[CPP]View Plain Copy
- -(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 status bar actions