iOS Development UI Chapter-Program startup principle and UIApplication

Source: Internet
Author: User

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

Related Article

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.