First, UIApplication
1. Brief introduction
(1) The UIApplication object is a symbol of the application, and a UIApplication object represents an application.
(2) Each application has its own UIApplication object, and is a singleton, if you try to create a new UIApplication object in the program, then the error prompt.
(3) This singleton object can be obtained by [Uiapplicationsharedapplication]
(4) An iOS program is created after the first object is the UIApplication object, and only one (through the code to get two UIApplication objects, the print address can see the address is the same).
(5) Use the UIApplication object to perform some application-level operations
2. Application-level operation examples:
1) Set the application icon in the upper right corner of the red reminder number (such as QQ message, the icon will show a new message, such as three-way bar. )
@property (nonatomic) Nsinteger applicationiconbadgenumber;
-(void) viewdidload
{
[Super Viewdidload];
Create and add a button
UIButton *btn=[[uibutton alloc]initwithframe:cgrectmake (100, 100, 60, 30)];
[Btn settitle:@ "button" forstate:uicontrolstatenormal];
[Btn Setbackgroundcolor:[uicolor Browncolor];
[Btn addtarget:self Action: @selector (OnClick) forcontrolevents:uicontroleventtouchupinside];
[Self.view ADDSUBVIEW:BTN];
}
-(void) OnClick
{
NSLog (@ "button click event");
Error, there can be only one unique UIApplication object that can no longer be created
UIApplication *app=[[uiapplication Alloc]init];
Get the UIApplication object for the program by Sharedapplication
UIApplication *app=[uiapplication Sharedapplication];
app.applicationiconbadgenumber=123;
}
2) Set the visibility of the networking indicator
@property (nonatomic,getter=isnetworkactivityindicatorvisible) BOOL networkactivityindicatorvisible;
Code and Effects:
Set up an indicator's networked animation
App.networkactivityindicatorvisible=yes;
3) Manage status bar
Starting with IOS7, the system provides 2 ways to manage the status bar
A. Through Uiviewcontroller management (each uiviewcontroller can have its own different status bar).
In IOS7, by default, the status bar is managed by Uiviewcontroller, and Uiviewcontroller can easily manage the visibility and style of the status bar by implementing the following methods
The style of the status bar-(Uistatusbarstyle) Preferredstatusbarstyle;
Visibility of the status bar-(BOOL) Prefersstatusbarhidden;
#pragma mark-to set the style of the status bar
-(Uistatusbarstyle) Preferredstatusbarstyle
{
Set to White
return uistatusbarstylelightcontent;
Default is Black
return uistatusbarstyledefault;
}
#pragma mark-set whether the status bar is hidden (no)
-(BOOL) Prefersstatusbarhidden
{
return NO;
}
iOS Development UI Chapter-Program startup principle and UIApplication